Show Menu

GIT - Everyday use Cheat Sheet by

A quick reference guide for everyday work with GIT.

Key concepts

Head is your current branch. You can see what HEAD points to by typing
cat .git/HEAD
Remotes are non-local reposi­tories you can interact with (push/­pull). The default remote is origin (you can see that using
git remote -v
Branches are a way of safely work on new features without messing other peoples work (one feature, one branch).
A commit is a change or a set of changes you wish to register and save.


Create a local repository
mkdir ./my_repo && cd ./my_repo && git init
Clone a repository from GitHub
Clone a specific branch from a repo
git clone -b development


List branches
git branch
git branch --list
Clone a specific branch
git clone -b <branch> <remote_repo>
git clone -b develo­pment git@gi­thu­­myp­roj­ect.git
Switch to an existing branch
git checkout <br­anc­h>
git checkout feat/r­obe­rt/­add­-pu­b-h­oli­day­s-2020
Switch to a new branch
git checkout -b <ne­w_b­ran­ch>
git checkout -b conf/m­arc­el/­use­-Ed­ito­rConfig
Push changes to a remote branch
git push origin <br­anc­h>
git push origin fix/pa­tri­ck/­rem­ove­-pa­ras­ite­-ch­ars­-fr­om-­con­fig­-file
Delete a branch
git branch -d <br­anc­h>
git branch -d feat/r­aja­/co­unt­-ap­i-f­ailures
Integrate your feature branch to the main
git merge <br­anc­h>
git merge main
Using branches, several developers are able to work together on the same code base, the same project.
git merge is not usually done manually, but is managed by your pull request system.

Getting out of (mild) troubles

Cancel untracked uncommited local changes
git reset --hard && git pull remote <remote_branch>

Basic config­uration

Set your name
git config --global "John Doe"
Set your email address
git config --global
Set your default editor
git config --global core.editor emacs

Dot files

Specifies intent­ionally untracked files that Git should ignore. Files already tracked by Git are not affected.
Gives attributes (end of line type, diff type, merge type...) to certain files.
Examples of .gitignore files: click here
Examples of .gitat­tri­butes files: click here

Basic workflow

Clone a repo
Create a new branch
git checkout -b conf/yu/add-api-endpoints-to-monitoring
Check repo status and current branch
git status
Add changes to next commit (track files)
git add -A
Commit with a message
git commit -m "Sometimes dogs are grey"
Refresh current local branch with remote branch
git pull origin development
Push changes to remote
git push origin conf/yu/add-api-endpoints-to-monitoring
git push uploads your commits to the remote reposi­tory.
git pull is a combin­ation of git fetch and git merge. It gets the updates from remote repository and applies the latest changes to your local.


Add one file to a future commit
git add <fi­le>
git add benchm­ark.c
Add all files to a future commit
git add -A
Commit with a message
git commit -m "<message>"
git commit -m "­Initial commit­"
Change the message of the latest commit
git commit --amend -m "<new_message>"
git commit --amend -m "­Bea­utiful commit­"
Cancel a commit
git log  -- oneline
git revert <co­mmi­t_i­d>
Git commits are checkp­oints in the develo­pment process which you can go back to later if needed.
Git commit saves your changes only locally.
git revert won't delete the commit, it will instead create a new one cancelling the other.


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Git Cheat Sheet
          The Basics of Accounting Cheat Sheet

          More Cheat Sheets by TME520

          Lantern Light for MSDOS keyboard mapping Cheat Sheet
          Slack messages formatting Cheat Sheet
          Top 30 linux shell tricks Cheat Sheet