Add ssh key to access github and simple git commands


Here are ways to add ssh key in Github, such that one can connect to github repositories without typing username and passwords.

For MAC Users:

To create an SSH Key, go to your terminal (or iTerm 2) and enter ssh-keygen. You will be prompted for a file in which to save the key (.ssh/id_rsa). There’s no need to enter anything, just press enter. When prompted for a passphrase, you can enter one or just press enter to ignore creating a passphrase.

Your SSH key has been saved to ssh/id_rsa.pub, run the command pbcopy < ~/.ssh/id_rsa.pub to copy this to your clipboard.

Now go to your Github account setting for Key: https://github.com/settings/keys and click ‘New SSH key’. Add any title you want, like ‘First SSH Key’, paste in your SSH key, and click the ‘Add SSH key’ button.

For PC Users:

To create an SSH Key, go to your terminal and enter ssh-keygen. You will be prompted for a file in which to save the key (.ssh/id_rsa). There’s no need to enter anything, just press enter. When prompted for a passphrase, you can enter one or just press enter to ignore creating a passphrase.

Your SSH key has been saved to ssh/id_rsa.pub, run the command cat ~/.ssh/id_rsa.pub to see your SSH key in the proper format. Copy the whole text string starting with ‘ssh’ to the end.

Now go to your Github account setting for keys: https://github.com/settings/keys and click ‘New SSH key’. Add any title you want, like ‘First SSH Key’. Paste your SSH key to the Key window, and click the ‘Add SSH key’ button.

There are a lot of complex functionalities of Git, but for 99% of work there are 4 things that you need to be able to do:

  1. Create a branch git checkout -b my-branch-name

  2. Add files that you want to queue up for saving.

    • To add all files: git add .

    • To add a specific file: git add path-to-file

  3. Save (commit) changes to the files that you added above. git commit -m "message about this commit. Ex: change button color to green."

  4. Sync your branch to Github so that you can later make a pull request. git push -u origin my-branch-name


Author: robot learner
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source robot learner !
  TOC