Summary
This page will go over how I setup git and some of the useful tip/tricks I wish I knew before.
Assumptions
- You use GitHub for your git activities
- You are using Linux/WSL/MacOS
Contents
Useful Links
Setting Up Github SSH Keys
Linux / WSL / MacOS
Generate a SSH Key1 or use a pre-existing one 2
In the terminal use the following command to generate a key.
ssh-keygen -t ed25519 -C "your_email@example.com"
Start the ssh-agent in the background.
eval "$(ssh-agent -s)"
> Agent pid 59566
Add your SSH private key to the ssh-agent.
ssh-add ~/.ssh/key_name
Now add the key to your github account
Copy the contents of your key and add to your github account under - New SSH Key
cat ~/.ssh/key_name.pub
You can test your connection with the following:
$ ssh -T git@github.com
> Hi USERNAME! You've successfully authenticated, but GitHub does not
> provide shell access.
Commands
Official cheat sheet 3
Setup
git config --global user.name “name” #Set the name that will be used in commits, Normally your username.
git config --global user.email “[valid-email]” #Set a email that will be used in commits.
git config --global color.ui auto #Add colouring to git commands.
Setup & Init
git init #Initialise an existing directory as a Git repository.
git clone [url] #Retreive entire repository from a hosted location via URL.
Stage & Snapshot
git status #Show modified files in working directory, staged for your next commit.
git add [file] #Add a file as it looks not to your next commit (Stage).
git reset [file] #Unstage a file while retaining the changes in working directory.
git diff #Diff of what is changed but not staged.
git diff --staged #Diff of what is staged but not yet commited.
git commit -m "[descriptive message]" #Commit your staged content as a new commit snapshot.