Git Cheat Sheet — Quick Reference Guide

A quick, well-organized Git cheat sheet covering basics to advanced commands — installation, setup, branching, merging, history management, remote repositories, and more.

Git Installation Commands

CommandDescription
Git for Windows stand-alone installerDownload and install Git for Windows from official site
sudo apt-get install gitInstall Git on Linux
brew install gitInstall Git with Homebrew on Mac OS
sudo port selfupdate
sudo port install git
Install Git with MacPorts on Mac OS
git --versionShow current Git version

Git Configuration & Setup

CommandDescription
git config --global user.name "Your Name"Set global Git username
git config --global user.email "youremail@example.com"Set global Git email
git config --global color.ui autoEnable colored output in terminal
git config --global alias.<alias-name> <git-command>Create custom alias for a Git command
git config --listList all Git configuration settings
git config --get <key>Retrieve value of a specific configuration key
git helpDisplay Git help documentation

Initializing a Repository

CommandDescription
git initInitialize new Git repository in current directory
git init <directory>Create Git repo in specified directory
git clone <repository_url>Clone repository from remote
git clone --branch <branch_name> <repository_url>Clone specific branch from remote

Basic Git Commands

CommandDescription
git add <file>Add specific file to staging area
git add . or git add --allAdd all modified and new files to staging
git statusShow current repo state (tracked/untracked files, branch info)
git status --ignoredShow ignored files too
git diffShow changes between working dir and staging area
git diff <commit1> <commit2>Show difference between two commits
git diff --staged or git diff --cachedShow changes between staging area and last commit
git diff HEADShow difference between working dir and last commit
git commitCreate commit with staged changes (opens editor)
git commit -m "<message>"Create commit with inline message
git commit -a or git commit --allCommit all modified/deleted files without staging
git notes addAdd note to commit/tag/object
git restore <file>Restore file to last commit state
git reset <commit>Move branch pointer, reset staging & working directory
git reset --soft <commit>Move branch pointer but keep staged & working directory changes
git reset --hard <commit>Reset repo to commit, discarding all changes
git rm <file>Remove file and stage deletion
git mv <old> <new>Rename or move file/directory

Git Commit (Updated Commands)

CommandDescription
git commit -m "feat: message"Create commit for new feature
git commit -m "fix: message"Commit bug fixes
git commit -m "chore: message"Commit routine tasks/maintenance
git commit -m "refactor: message"Commit code refactoring/improvements
git commit -m "docs: message"Commit documentation changes
git commit -m "style: message"Commit styling/formatting changes
git commit -m "test: message"Commit test-related changes
git commit -m "perf: message"Commit performance improvements
git commit -m "ci: message"Commit CI system-related changes
git commit -m "build: message"Commit build process changes
git commit -m "revert: message"Commit reversion of a previous commit

Branching and Merging

CommandDescription
git branchList all branches
git branch <branch-name>Create new branch
git branch -d <branch-name>Delete branch
git branch -aList all local and remote branches
git branch -rList all remote branches
git checkout <branch-name>Switch to branch
git checkout -b <new-branch-name>Create and switch to new branch
git checkout -- <file>Discard changes in file
git merge <branch>Merge specified branch into current
git logShow commit history of current branch
git log <branch>Show commit history of specified branch
git log --follow <file>Show commit history of a file, including renames
git log --allShow commit history of all branches
git stashStash changes in working directory
git stash listList all stashes
git stash popApply and remove most recent stash
git stash dropRemove most recent stash
git tagList all tags
git tag <tag-name>Create lightweight tag at current commit
git tag <tag-name> <commit>Create lightweight tag at specified commit
git tag -a <tag-name> -m "<message>"Create annotated tag with message

Remote Repositories

CommandDescription
git fetchFetch changes from remote repository
git fetch <remote>Fetch changes from specified remote
git fetch --pruneRemove remote branches that no longer exist
git pullFetch and merge changes from remote
git pull <remote>Fetch and merge from specified remote
git pull --rebaseFetch and rebase current branch
git pushPush commits to remote repository
git push <remote>Push commits to specified remote
git push <remote> <branch>Push commits to remote branch
git push --allPush all branches to remote
git remoteList all remotes
git remote add <name> <url>Add new remote repository
git remote rm <remote>Remove remote connection
git remote rename <old_name> <new_name>Rename remote connection

Git Comparison

CommandDescription
git showShow details of specific commit
git show <commit>Show details of specified commit

Git Logging and Reviewing Commands

CommandDescription
git reflogShow reference logs (history of HEAD)
git blame <file>Show line-by-line last modifier of file
git bisect startStart binary search for bug
git bisect good <commit>Mark commit as good
git bisect bad <commit>Mark commit as bad
git bisect resetEnd binary search
git describeShow human-readable commit description
git cherry-pick <commit>Apply changes from a commit onto current branch
git revert <commit>Create a new commit that undoes changes of specified commit