When using github, you usually have to enter your login credentials each time you push. You could solve this problem by saving the credentials or by setting up ssh for your account. In this post, the process of adding and using ssh keys will be explained.
I'm using git bash, if you use git gui/sourcetree/etc. you should consider switching, at least for this process.
At first, SSH keys are generated. The command for this is the following:
ssh-keygen -t rsa -b 4096 -C "firstname.lastname@example.org"
The flag t is used to describe the type, which is rsa. The next flag, b, describes the amount of bytes which is 4096. The last flag, C, describes the label of the key pair. Just set this email to the one you use to push to github.
After pressing enter, you are prompted to add a location to where the files should be saved. Just use the defaults here by pressing enter. After that, you can enter a passphrase. This will encrypt your key. I recommend doing that, if you'd like to read more about why to do that, you can go on here.
After a short time, you have two files in an .ssh-folder inside your home directory. The public key is marked by the .pub-ending. Enter the following commands to add the key to your ssh-agent, so you won't have to enter the passphrase each time the keys are used:
eval $(ssh-agent -s) ssh-add /path/to/private-key
This is all you need to do on your computer. You now need to add the public key to your github account. Log in on https://github.com and go to settings - SSH and GPG keys - New SSH key. Enter a title to be able to recognize the key later. After that, enter the content of your public keys file. You can log this to your terminal and copy and paste it using
On Mac, you can use pbcopy instead of clip. On Linux, just use cat or similar. (I think you basically know your stuff then.) Save the key to complete the process.
That's basically it, your keys are now linked and you can push to github. Note that github uses different urls for https and ssh, looking like this:
# HTTPS https://github.com/username/repo.git # SSH email@example.com:username/repo.git
You can check your url using git remote -v and eventually change this by using git remote set-url origin url. (Use your specific url here).