-
Notifications
You must be signed in to change notification settings - Fork 3
Tutorial: Git
To see if you already have git, open a terminal and type:
$ git help
If you have it, you will see a help message and you can skip to the next section. Otherwise, your system might tell you how to install it.
This document is mainly about setting up Git. See here for Git basics.
If you don't like reading, you can also learn git via this interactive tool: https://learngitbranching.js.org/
Note: Git vs Github
Git is a distributed version control tool that can manage a development project's source code history, while GitHub is a cloud-based platform built around the Git tool. Git is a tool a developer installs locally on their computer, while GitHub is an online service that stores code pushed to it from computers running the Git tool.
Since setting up ssh makes interventions easier, we recommend you to setup ssh keys on your machine.
Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without supplying your username or password at each visit.
Below is a compiled guide from the pieces in the link above.
SSH Keys are secure local keys that you can register on GitHub so that you don't have to enter your credentials each time you're accessing a remote repository. By setting up an SSH connection and registering the credentials on GitHub itself, all the verification/identification steps are taken care of by the SSH agent and you can simply push/pull the code.
In order to check:
ls -al ~/.ssh
Sample Output:
ls -al ~/.ssh
total 32
drwx------ 2 jamiecho jamiecho 4096 Sep 9 22:58 .
drwxr-xr-x 83 jamiecho jamiecho 4096 Oct 1 18:05 ..
-rw------- 1 jamiecho jamiecho 3247 Jul 27 17:17 id_rsa
-rw-r--r-- 1 jamiecho jamiecho 747 Jul 27 17:17 id_rsa.pub
-rw------- 1 jamiecho jamiecho 6870 Oct 1 02:56 known_hosts
-rw------- 1 jamiecho jamiecho 6426 Sep 9 21:56 known_hosts.old
You should find any one of id_dsa.pub, id_ecdsa.pub, id_es25519.pub, id_rsa.pub, ...
However, in most cases (i.e. new to setting up the environment), you'll be setting up Git in a computer without preconfigured ssh-keys. In this case, you should generate a new SSH key. This step is explained in the next section.
-
Generate the key by running the command below in the terminal (Do not copy-paste the below script directly):
ssh-keygen -t rsa -b 4096 -C "[email protected]"
-
When you're prompted to "Enter a file in which to save the key," press Enter.
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
This accepts the default file location.
-
At the prompt, type a secure passphrase. For more information, see Working with SSH key passphrases.
Enter passphrase (empty for no passphrase): [Type a passphrase] Enter same passphrase again: [Type passphrase again]
-
Ensure ssh-agent is enabled:
# start the ssh-agent in the background eval "$(ssh-agent -s)" Agent pid 59566 # sample output
-
Add your SSH Key to the ssh-agent:
ssh-add ~/.ssh/id_rsa
-
Install Xclip, which is a program that allows you to copy/paste things with CLI.
# install xclip sudo apt-get install xclip # copy id_rsa.pub to clipboard xclip -sel clip < ~/.ssh/id_rsa.pub
-
Go to your Profile Page, and click Settings.
-
In the user settings sidebar, click SSH and GPG keys.
-
Click New SSH key or Add SSH key.
-
In the "Title" field, add a descriptive label for the new key. For example, if you're using a personal Mac, you might call this key "Personal MacBook Air".
-
Paste your key (from step 1) into the "Key" field.
-
Click Add SSH Key.
-
If prompted, confirm your GitHub password.
- Learn Git online: https://learngitbranching.js.org/
- amgit by Allen Downey: https://github.com/AllenDowney/amgit/tree/master/en
- Git tutorials by Atlassian: https://www.atlassian.com/git/tutorials/setting-up-a-repository
If you need help, come find Merwan Yeditha [email protected] or Audrey Lee [email protected]!