Stop User/Password Prompt when Pushing to GitHub

I began using GitHub for Mac to clone my repositories down to my Mac. Then, every time I committed and pushed something up to GitHub, I got prompted for my username and password, like this:

$ git push

After a few commits, this got annoying very quickly. I was sure that I had setup my SSH keys correctly, and  retested them to make sure. After some searching, I found the source of the problem: GitHub for Mac clones your repo using HTTPS, which subsequently causes the authentication prompt when performing a push.

Navigate to your cloned directory, and examine the .git/config file. You will see a section entitled [remote “origin”] that looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url =

Note the “url” directive pointing to your GitHub repo with the https protocol. This is what we have to change to stop the repeated authentications. From a command prompt inside your local repo directory, issue this command to change the protocol, substituting your login name and repo name where appropriate:

git config remote.origin.url [email protected]:your_username/your_project.git

In the instance of my repo, running the command looks like this:
git config remote.origin.url [email protected]:cosjef/first_app.git

After running the command, reopen your .git/config file, and you now will see that the protocol has changed:

[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = [email protected]:cosjef/first_app.git

If you now try a push operation, you should not be challenged for a username and password.
  • Oldie but a goodie. Thanks for the share!

  • sarabande

    Thanks, after a few password prompts I myself got angry.

  • sutoa

    Thanks for the tip. This is exactly what I am looking for!

  • Sydney

    Awesome tip. This should still be very secure right?

  • Bob

    Thanks for explaining this unusual git-ism