0.0 – CREATE AN ACCOUNT ON GITHUB
First you need to create a GitHub account. Go to https://github.com/ and “sign up”
1.0 – SETTING UP GIT
Download and install the latest version of Git by opening the terminal and running:
sudo apt-get install git
Then you need to configure your account with the same name and email from your GitHub account.
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL ADDRESS"
2.0 – AUTHENTICATING GIT OVER SSH
When you connect to a GitHub repository from Git, you’ll need to authenticate with GitHub using either HTTPS or SSH. Here we will overview the most common security protocol SSH.
2.1 – CHECK FOR EXISTING SSH KEYS
Before you generate an SSH key you should check on your computer for other keys previously generated, so you don’t replace or mess up other accesses.
ls -al ~/.ssh
This command will list the files in your .ssh directory, if they exist.
If the result comes out something like:
ls: cannot access '/home/yourpcname/.ssh': No such file or directory
This means you don’t have any SSH key, so please move to the next chapter.
If you do have other keys, please take notes of folder names so when prompted to add a location for this new SSH you do not mess up the previously generated codes, or just use that previously generated key to connect to GitHub.
2.2 – GENERATE A NEW SSH KEY
Paste the following text below and replace in your GitHub email address
ssh-keygen -t rsa -b 4096 -C "email@example.com"
This will create a new ssh key based on the email you provided.
The following message will pop up then:
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
Enter to confirm the default location for the key.
Then you’ll need to provide a secure passphrase.
Enter passphrase (empty for no passphrase): [Type a passphrase] Enter same passphrase again: [Type passphrase again]
3.0 – ADDING A NEW SSH KEY TO YOUR GITHUB ACCOUNT
Download and Install xcplip.
$ sudo apt-get install xclip
and copy the contents of the
id_rsa.pub file to your clipboard.
$ xclip -sel clip < ~/.ssh/id_rsa.pub
Go to your GitHub account Settings>SSH and GPG keys and click
new SSH key
Add the tittle you prefer and paste (ctrl+v) your new key into the key field.
Add SSH key, confirm your GitHub password and you are done.
4.0 – TESTING YOUR SSH CONNECTION
For testing your SSH connection please paste the following:
ssh -T firstname.lastname@example.org
Confirm the authenticity of GitHub by writing down
yes on the following message:
The authenticity of host 'github.com (220.127.116.11)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you sure you want to continue connecting (yes/no)?
Now you should see a confirmation message with your username.
5.0 – CLONING A REPO
Now this is where the fun begins. Go to your GitHub account. On the far right you’ll see the list of repo’s you are currently owning or working on.
Click on the one you’d like to have a local working copy and again on the far right you’ll see the clone or download icon.
Click on it and copy the address. Go back to your terminal and look for a location on your disk where you’d want to have these files available. For demonstration purposes we will use the Desktop and create a new directory inside it.
cd ~/Desktop mkdir "yourdirname" cd "yourdirname"
Then start running the Git commands. First one is Git Clone.
git clone "paste/the/copied/url/here"
6.0 – PUSH MANTRA
Now that you already cloned the remote repo to your pc, you can now start working on its content.
After finishing all your changes you’d want to push them back to the remote repo on GitHub. For doing so there’s a mantra you should follow:
cd ~/Desktop/"yourdirname"/"yourgithubdirname" git pull git add . git status git commit -m "short description of the changes you made" git push
Be careful when running this set of commands. They can seriously harm the remote repository’s latest version.
git status Git will let you know the changes you are proposing. If you notice something wrong or weird, please stop the mantra and contact your repository administrator or check for answers or solutions to the problem.
7.0 – GOOD PRACTICES
There’s a set of good practices for working with repos:
- keep your files small and manageable,
- always use small case words on your file names,
- never use spaces when naming a file, as spaces are also special characters,
- use short names for your file names,
- never use special characters when naming a file! please check this list
- be careful with hidden files like .DS_Store. Activate your show hidden files option (ctrl+h)