Today I learned… how to save my GitHub username and password so I don’t have to re-enter them every time I push something to GitHub from my Windows machine.
A bit of backstory:
I recently set up git on my Windows 7 machine using Git for Windows (mysisgit). That process went smoothly and I feel right at home in my little emulator, Git Bash, using all the same commands I already know and love from my Mac.
If you’re used to using git on a Mac and have to work on a Windows machine for whatever reason, I highly recommend mysisgit.
Credential check… every time!
Everything was going great until I pushed my changes. Every push triggered a new credentials check!
$ git push origin master Username for 'https://github.com': xyz Password for 'https://xyz@github.com':
I don’t want to enter my GitHub username and password every time I push something.
HTTPS vs. SSH?
So I hit the Google and found this StackOverflow question, where some helpful folks say the problem results from connecting over HTTPS instead of SSH, but GitHub’s help documentation recommends connecting over HTTPS, not SSH.
I’m hesitant to disobey the word of GitHub, so instead of relying on SSH, I followed GitHub’s instructions to use a credentials helper.
Credentials Helper Setup
However… GitHub’s explanation of how to cache your password with the credentials helper aren’t very clear. They tell you to enter this line and then don’t tell you what to do next.
Here’s what I did – worked for me.
In your Git Bash window, enter this line:
$ git config --global credential.helper wincred
Now push a change to Github and enter your credentials – this is where your username and password information gets saved to the credential helper.
You won’t get any feedback telling you that, but you can confirm it worked by pushing another change. This time, you shouldn’t have to enter your credentials again.
But I have this problem on Linux!
Try this: Caching your GitHub password in Git
$ git config --global credential.helper cache
You saved my day! Thanks a lot! :D
Just want to say thank you very much :D
God bless your soul you saved my life i owe u big time!
Wow ! easiest solution after going through few links !
Btw how do i stop caching or saving password (just in case if i ever need it)
Cheers !
To get a more permanent solution if you can’t be bothered with entering you credentials every now and again, even if you set the cache timeout to next year:
git config –global credential.helper ‘cache –timeout 30758400’
And you are not to worried about your computer being compromised see the solution in this stackoverflow answer where you create an ssh key and enter it in the github settings of your repo and never have to enter a username or password.
http://stackoverflow.com/questions/8588768/git-push-username-password-how-to-avoid#answer-8588786
It Worked well for me thanks
This was perfect, thank you much!
Thanks a lot! I don’t suppose this would work in Git CMD. Or would it?
great !! worked for me !!
Its simple than that in windows with netrc file
John Carter@JohnCarter-PC MINGW64 ~
$ cat ~/_netrc
machine github.company.com
login username
password password
machine github.com
login username
password password
machine bitbucket.org
login username
password password
Huge Thanks!
Thank you very much
Wow. That is so elegant and logical and clearly explained. Keep it up! I follow up your blog for future post.
Works for me
Thanks man
Thanks :)
It helped me a lot ty
It is really good without entering user name and password for every activity
This saved my time, it was annoying to re-enter password every time I do git pull.
Thanks you so much :).
Nice article