Git Basics

Some basics about Git and GitHub.

Although there are many tutorials online, I still want to record some of them here for my own reference.

1
2
git config --global user.name "Your Name Here"
git config --global user.email "your_email@youremail.com"

NOTE: your_email@@youremail.com should be the noreply email address of your GitHub account.

1
2
git clone https://github.com/<username>/<repo-name>.git # https
git clone git@github.com:<username>/<repo-name>.git # SSH

First check for existing SSH keys on your computer by running:

1
2
ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist

Check the directory listing to see if you have files named either id_rsa.pub or id_dsa.pub. If you don’t have either of those files then read on, otherwise skip the next section.

  1. Open Terminal.

  2. Paste the text below, substituting in your GitHub email address. This creates a new ssh key, using the provided email as a label.

    1
    
    ssh-keygen -t ed25519 -C "your_email@example.com"
    
  1. Start the ssh-agent in the background.

    1
    
    eval "$(ssh-agent -s)"
    
  2. Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.

    1
    
    ssh-add ~/.ssh/id_ed25519
    
1
ssh -T git@github.com

See GitHub documents