From charlesreid1

If git keeps pestering you for your Github username and password, the problem is that all of your repositories are being checked out using their HTTPS url to Github. This always requires you to enter your password.

Instead, you should set up your computer to be identified by Github, which will allow you to check out repositories using their git URL to Github. This will be an identical repository, but accessed using a different authentication system (public/private keys over SSH). This is a much more efficient and safe method for authenticating.

The steps:

  • Create your public private key pair
  • Tell Github your public key
  • Change the remotes of your local cloned copy to use the git URL instead of the HTTPS URL

Step 1: Set up Github SSH Keys

Useful instructions: https://help.github.com/articles/generating-ssh-keys

If you don't have a public key, you will need to make one.

If you have one already, your public key is in ~/.ssh/id_rsa.pub so give Github the contents of that file. Log into your Github account, click account settings, and find the SSH Keys option. Add a new SSH key, and copy and paste the contents of ~/.ssh/id_rsa.pub to the box and save the key.

$ cat ~/.ssh/id_rsa.pub

........blah..........

Make sure you don't give Github your private key, which would be a bad idea. Your private key is in ~/.ssh/id_rsa (no pub extension means it is private).

Step 2: Switch Repos from HTTPS to SSH

You can switch your repos from HTTPS to SSL without opening the browser. First check the repo url using the git remote command:

$ git remote -v 
origin   https://github.com/user/repo.git (fetch)
origin   https://github.com/user/repo.git (push)

Find the addresses of the github remotes, and switch the protocol from HTTPS to GIT (note the syntax):

$ git remote set-url origin git@github.com:user/repo.git