This came up in a discussion with a friend earlier today when he exclaimed “‘git push’ requires a username and password every time I execute it!” While I’m not sure exactly why this happens, I’m glad to tell you I have found an easy solution.
git push like you normally do, but instead of getting the nice block of text letting you know your commits were pushed to the remote repository, you get a message that says
Username for 'https://github.com':. Well, damn…it was working the last time I tried that.
Username for 'https://github.com':
Like I said, I’m not sure why this happens, but after having to find ways around before, I’ve now found the straight line solution instead the solution that required going around the river and through the woods.
Before we attempt this solution, verify that the problem we fix in this solution is the problem you’re having.
Use the command
git config --local -l to see what the local configuration file for this repository looks like. There should be a line that starts with
remote.origin.url=. If line looks something like
remote.origin.url=https://github.com/your_username/your_repository_name.git, then good news, we can cure your heartache.
This is what your local config file will most likely look like:core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true core.ignorecase=true core.precomposeunicode=true remote.origin.url=https://github.com/your_username/your_repository_name.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master
Since we’ve confirmed that your remote origin url is set to the https url instead of the ssh url, we need to get your config file set to use the ssh url.
We need to open an editable version of your config file. To do this, enter
git config --local -e so your config file will open in a handy dandy text editor.
While the file will look a little different than the terminal output, change the line we singled out before and replace all the text after the ‘=’ sign to follow the convention that matches
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [remote "origin"] url = [email protected]:your_username/your_repository_name.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master
Once you’ve gotten that file saved, close it and try again to
Need more help? Get in touch.
This time, you should no longer have the issue that ‘git push’ requires a username and password every time.