Setup git with extra tips and tricks

Home
Author: avolent
Updated on: May 2024
/tools/setup git with extra tips and tricks

Summary

This page will go over how I setup git and some of the useful tip/tricks I wish I knew before.

Assumptions

Contents

  1. Useful Links
  2. Setting up github SSH Keys
  3. Commands
  4. References

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

add_ssh_key.png

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. 

Branch & Merge

Inspect & Compare

Tracking Path Changes

Ignoring Patterns

Share & Update

Rewrite History

Temporary Commits

References

Footnotes

  1. Generating SSH keys for Github

  2. Checking for existing SSH Key

  3. GitHub Cheat Sheet

CSS is from Latex.css | Wiki built by avolent.io | Repository located on Github

Return to top