A quick, well-organized Git cheat sheet covering basics to advanced commands — installation, setup, branching, merging, history management, remote repositories, and more.
| Command | Description |
|---|---|
| Git for Windows stand-alone installer | Download and install Git for Windows from official site |
sudo apt-get install git | Install Git on Linux |
brew install git | Install Git with Homebrew on Mac OS |
sudo port selfupdatesudo port install git | Install Git with MacPorts on Mac OS |
git --version | Show current Git version |
| Command | Description |
|---|---|
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 auto | Enable colored output in terminal |
git config --global alias.<alias-name> <git-command> | Create custom alias for a Git command |
git config --list | List all Git configuration settings |
git config --get <key> | Retrieve value of a specific configuration key |
git help | Display Git help documentation |
| Command | Description |
|---|---|
git init | Initialize 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 |
| Command | Description |
|---|---|
git add <file> | Add specific file to staging area |
git add . or git add --all | Add all modified and new files to staging |
git status | Show current repo state (tracked/untracked files, branch info) |
git status --ignored | Show ignored files too |
git diff | Show changes between working dir and staging area |
git diff <commit1> <commit2> | Show difference between two commits |
git diff --staged or git diff --cached | Show changes between staging area and last commit |
git diff HEAD | Show difference between working dir and last commit |
git commit | Create commit with staged changes (opens editor) |
git commit -m "<message>" | Create commit with inline message |
git commit -a or git commit --all | Commit all modified/deleted files without staging |
git notes add | Add 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 |
| Command | Description |
|---|---|
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 |
| Command | Description |
|---|---|
git branch | List all branches |
git branch <branch-name> | Create new branch |
git branch -d <branch-name> | Delete branch |
git branch -a | List all local and remote branches |
git branch -r | List 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 log | Show 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 --all | Show commit history of all branches |
git stash | Stash changes in working directory |
git stash list | List all stashes |
git stash pop | Apply and remove most recent stash |
git stash drop | Remove most recent stash |
git tag | List 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 |
| Command | Description |
|---|---|
git fetch | Fetch changes from remote repository |
git fetch <remote> | Fetch changes from specified remote |
git fetch --prune | Remove remote branches that no longer exist |
git pull | Fetch and merge changes from remote |
git pull <remote> | Fetch and merge from specified remote |
git pull --rebase | Fetch and rebase current branch |
git push | Push commits to remote repository |
git push <remote> | Push commits to specified remote |
git push <remote> <branch> | Push commits to remote branch |
git push --all | Push all branches to remote |
git remote | List 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 |
| Command | Description |
|---|---|
git show | Show details of specific commit |
git show <commit> | Show details of specified commit |
| Command | Description |
|---|---|
git reflog | Show reference logs (history of HEAD) |
git blame <file> | Show line-by-line last modifier of file |
git bisect start | Start binary search for bug |
git bisect good <commit> | Mark commit as good |
git bisect bad <commit> | Mark commit as bad |
git bisect reset | End binary search |
git describe | Show 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 |