As you make more changes in your local repository, you'll want to push those commits to the remote repository more and more. Typing your GitHub credentials over and over can get tiresome. In order to suppress the username/password challenge every time you
git push, you need to authenticate with GitHub from the command line. GitHub recommends two ways to handle authentication. We will cover both of them here.
You may have noticed that when we added the remote URL with the
git remote command, we used an
https:// URL. This is the recommended way to connect with remotes on GitHub. It is important to note that here because Password Caching only works if the remote URL has been cloned or added with
https://. GitHub provides instructions for Mac OSX, Windows and Linux on setting up password caching. Follow the instructions on the GitHub page to set this up for your OS. On Mac and Linux you can use credential helper, a command line tool to cache the password. On Windows, you have the option to use GitHub's GUI or a command line tool.
To work with remote repositories using
https://, make sure to add or clone the remote repository using the appropriate protocol. For example, on GitHub, the sidebar allows you to select the protocol to connect:
You may also decide to connect to GitHub repositories using SSH, in which case you will authenticate using SSH keys instead of a username and password. This might also be the case in companies that have internal hosted repositories and require developers to use SSH. It's important that you are aware of SSH as it is also how code is distributed and pushed to production servers, such as deploying on Heroku.com.
The important thing to note here is that with SSH, you use SSH keys instead of username/password authentication. GitHub provides great instructions on setting up SSH and Generating SSH Keys on every operating system. Follow the steps on GitHub's page to generate and upload keys. A nice exercise is to try and switch your repository from HTTPS to SSH by changing your remote repository URLs and verify that it works.
SSH is an advanced topic and many times new developers can get stuck on this. We suggest you use HTTPS and password caching for now to keep the momentum and visit this later.
If you do try to connect using SSH, make sure to use the SSH URL from GitHub's sidebar: