Tuesday, June 3, 2014

Configure Git to only ask password WHILE pushing to remote repository

Configure Git to only ask password WHILE pushing to remote repository


You could tell git to store your credentials using the following command:


git config --global credential.helper store

git config --global credential.helper cache

Using this method, you only need to enter your username and password once and git will never ask for it again.

You can also go for caching instead which will store your password after having typed it once in a session for some period of time.
You can set the timeout yourself if your not happy with the default:


git config --global credential.helper 'cache --timeout=600'

Once again this is not always ideal.

What you should really be using is the ssh protocol to push and pull your data. This should work with proxies without any issues so you should definitely give it a go.

You can set it up by setting your remote url as follows:


git remote set-url origin git@github.com:<username>/<project>.git

git remote add origin https://{your_username}:{your_password}@github.com/{your_username}/repo.git

ex:- git push origin master


If you are using another hosting service like bitbucket, just replace "github.com" with your providers domain.
Once you do that, you will need to set up a public and private key pair for communication between github and your computer. 

There is a very good tutorial on how to set it up here. If you are using Linux or MacOSX you simply need to follow the steps when running the command ssh-keygen.
After that, you can get an ssh agent to store your password for you which is typically more secure. Ssh agents usually ask you to input your password just once after turning on your computer - but after that it should do everything automatically for you.
The ssh agent you use will depend on your operating system but it shouldn't be hard to set up.

1 comment:

  1. Thanks for your help. Its a quick reference to git's password less pull push request.

    ReplyDelete