Git cheatsheet

Quick reference for Git commands and workflows

Git Cheatsheet

Common Git commands with descriptions

All
Configuration
Repository
Basic
Branching
Remote
History
Undoing
Stashing
Tags

Configuration

git config --global user.name "Name"
git config --global user.email "email"
git config --list

Repository

git init
git clone <url>
git status

Basic

git add .
git add <file>
git commit -m "message"
git commit --amend
git diff
git diff --staged

Branching

git branch
git branch <name>
git checkout <branch>
git checkout -b <name>
git merge <branch>
git rebase <branch>
git branch -d <name>

Remote

git remote -v
git remote add origin <url>
git fetch origin
git pull origin <branch>
git push origin <branch>
git push -u origin <branch>

History

git log
git log --oneline
git log --graph --oneline
git blame <file>

Undoing

git reset HEAD <file>
git checkout -- <file>
git revert <commit>
git reset --hard HEAD~1

Stashing

git stash
git stash pop
git stash list
git stash drop

Tags

git tag <name>
git tag -a <name> -m "msg"
git push origin --tags

Semantic versioning explained

TL;DR

What is Git cheatsheet?

Git is a distributed version control system created by Linus Torvalds in 2005. It tracks changes to files over time, allowing multiple developers to collaborate on the same codebase, branch independently, and merge changes. This cheatsheet covers the most-used commands organized by workflow stage.

Common use cases

  • Daily workflow: look up the exact syntax for staging, committing, branching, and merging
  • Onboarding: reference for developers new to Git who need to connect command names to their purpose
  • Recovery: find the right command to undo a change, reset a branch, or recover a deleted commit

Frequently asked questions

What is the difference between git pull and git fetch?

git fetch downloads new commits and branches from the remote but does not change your working directory or current branch. git pull is a shorthand for git fetch followed by git merge (or rebase). Use git fetch when you want to see what changed before integrating.

What is the difference between git reset and git revert?

git reset moves the branch pointer backward, effectively removing commits from history (use with caution on shared branches). git revert creates a new commit that undoes the changes of a previous commit without rewriting history. Use git revert on shared branches; use git reset only on local commits.