Git Commands Cheatsheet

Harsh Seksaria
Version Control System, Git and GitHub
2 min readApr 2, 2021

--

Hey there! Hope you’re doing well.

In the last blog, we saw what merge conflicts mean. Then we created a conflict and learned how to resolve it. Here is a cheat sheet for all the Git commands that you use in a local system.

To install Git

Check my previous blog

Initialize Git repo

git init

Set basic user configuration variables

git config --global user.name <your_name>git config --global user.email <your_email_id>

These are used in commit logs to indicate who made that particular commit.

See the list of configuration variables

git config --list

Staging files

git add .orgit add -Aorgit add file_name //to track only a particular file(s)
git rm --cached <file_name> //to unstage a file

Repository status

git status

Commit

git commit -m "commit_message"
//if you dont give "-m" and the commit message, it will open an editor to type the commit message there
orgit commit -a -m "commit_message"

Append a commit

git commit --amend -m "updated commit message" //to edit only the commit message of the last commitorgit commit --amend --no-edit //to modify files and include in last commit

Log of the commits

git log

Show differences in various commits

git diff

Branches

Create a new branch

git branch <new_branch_name>

Checkout to another branch

git checkout <that new branch name>orgit checkout -b <new_branch_name> //to create a new branch and automatically switch to it

Delete a branch

git branch -d <branch name>orgit branch -D <branch name> //to force delete a branch

List of all the branches

git branch

Merge two branches

//checkout to the branch you want to merge togit merge <branch you want to merge>

Abort a merge

git merge --abort

Git log as a graph

git log --all --decorate --graphorgit log --graph --oneline

Check out the detailed blogs on all the above topics here.

My name is Harsh Seksaria. I like to write about the topics simplifying them as much as possible for you to understand without unnecessary effort. Still, sometimes something may not be very clear. If you find any mistake, error, or you have a suggestion, just mail me. I’ll try to improve it asap.

My email: harsh20.freelance@gmail.com

My LinkedIn: www.linkedin.com/in/harshseksaria

--

--

Harsh Seksaria
Version Control System, Git and GitHub

MSc Data Science @ Christ (Deemed to be University), Bangalore, INDIA