I have a git repository on an internal server and now want to have a scheduled task that automatically pulls changes to my local version. Found the GitPython package, which seems to be exactly what I need, but can't get it to work due to the password protection of the repo.
I have already cloned the repo to my local path (git clone git#LOCAL_IP:/repo/MY_GIT.git .) and will get prompted for the password every time I execute git pull from the command line (fair enough). According to How can I call 'git pull' from within Python?, I then tried exactly this
import git
g = git.cmd.Git(MY_LOCAL_PATH)
g.pull()
and (of course) get an error:
...
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
cmdline: git pull
stderr: 'Permission denied, please try again.
Permission denied, please try again.
...
Unfortunately, from the many answers around the web dealing with PythoGit, I found none that tells me how I can set the password (I know that you should never ever hardcode passwords, but still...).
You can save credentials within git so that every git client can access them and won't ask the user. See How can I save username and password in Git? for details on how to do that.
Related
I'm executing a command 'git push' and get error.
My remote repository is ahead of the local one.
I want to find out what changes have occurred on the remote repository.
Assuming you don't want to pull those changes yet, you can accomplish this with git log. First run git fetch to update your local refs. Then you'll want to run git log my-branch..origin/my-branch. This will show you commits on origin/my-branch (i.e. remote), which do not exist in your local repository.
Yesterday I just installed this script on my Macbook because I was having issues with the git credentials being stored in the keychain and after these expired I was getting error 403. I found that script that claims to periodically check for those credentials and delete them to avoid that kind of problems.
The problem is that every time I do any git command, my console says:
$ git pull
bad input: SgSNnX3
Already up to date.
As we can see, it does the git operation without problems but seems like something else is happening before executing the git command. I already uninstalled the script mentioned earlier but the annoying message still showing up.
Does anyone know what can I do to stop that message?
You can open ~/.gitconfig from any terminal you have and remove the cache and wincred helpers.
I am doing the reddit pygame boggle challenge. On my laptop it is in a directory called Boggler, but at sourceforge it is called pygame-boggle. When I do 'git push -u origin master' it gives the error in the title. What am I doing wrong? How do I get it to push?
I followed the instructions here: https://sourceforge.net/p/pygame-boggle/code/ref/master/
Have you initialized the repo? It seems like you haven't.
Run the command git init to set up a git repo. Then, add a remote to your repo (wherever it may be, github or bitbucket or any other site) by running the command
git remote add <url to remote here>
In Python, using GitPython, I need to git push to a HTTPS remote repository on BitBucket.
After running the repo.git.push() command, it will return -as expected-:
bash: /dev/tty: No such device or address
error: failed to execute prompt script (exit code 1)
fatal: could not read Password for 'https://username#bitbucket.org': Invalid argument'
But Python will give me no change to enter the password like in the console.
How can I "attach" the password to the git push command or how can simulate a console password entry in Python?
It is important to note that unfortunately using SSH is not an alternative (the script should not requiere any further action to user that receives it and that wants to git push). I'm looking to "attach" the password into the command or to "simulate" a text entry on it.
What you are attempting to is skirt past security.
You need to create a pair of ssh keys.
Then, log-on to your bitbucket account's website and upload your public key.
Store your keys in your ~/.ssh directory.
When you have your keys setup you will not be prompted for a password anymore.
Here is more information about working with SSH keys: https://help.github.com/articles/generating-an-ssh-key/
I would like to enter the name and password for git and the password for github from a python/shell script
But :
echo mypasswd | hg push
As :
echo myname mypasswd | git push origin master
Does not work
You can use:
git pull https://[user]:[passwd]github.com/[account]/[repo].git [branch]
Or add it as a remote:
git remote add origin https://[user]:[passwd]#github.com/[account]/[repo].git
If you want to keep the name origin for the new remote, you should delete the old one first by using git remote remove origin
Generally, when you want to provide answers to interactive commands you'll do it with something like this:
myCommand <<EOF
some answer
some other answer
EOF
But I'm afraid you can't use this kind of redirection / piping to provide passwords to your commands. As #Fidel pointed it out, you should check the expect command for that.
Also, you should authenticate on your SCM using rsa keys ;)
For Mercurial, you should take a look at how you can store HTTPS credentials. There are several options: you can store the password in a config file, you can use the keyring extension or you can hard-code it into the URL:
hg pull https://username:password#host/repo
Only put the password into the URL if you're on a trusted machine — other people logged into the machine will be able to see the password while your hg pull is running.