---
title: "Git Commands Cheatsheet | FindUtils"
description: "Common Git commands for setup, commits, branches, merges, history, stashes, and remote operations."
url: https://findutils.com/cheatsheets/git-commands/
---

# Git Commands Cheatsheet

Common Git commands for setup, commits, branches, merges, history, stashes, and remote operations. 55 commands in 8 sections, filed under [Git & Version Control](https://findutils.com/cheatsheets/git/).

## Setup & Config

- `git init`: Initialize a new Git repository
- `git clone <url>`: Clone a remote repository
- `git config --global user.name "Name"`: Set your name for all repos
- `git config --global user.email "email"`: Set your email for all repos
- `git config --list`: Show all configuration settings

## Staging & Committing

- `git status`: Show working tree status
- `git add <file>`: Stage a specific file
- `git add .`: Stage all changes in current directory
- `git add -p`: Interactively stage hunks
- `git commit -m "message"`: Commit staged changes with message
- `git commit --amend`: Modify the last commit
- `git reset HEAD <file>`: Unstage a file
- `git checkout -- <file>`: Discard changes in working directory

## Branching & Merging

- `git branch`: List all local branches
- `git branch <name>`: Create a new branch
- `git checkout <branch>`: Switch to a branch
- `git checkout -b <branch>`: Create and switch to new branch
- `git switch <branch>`: Switch to a branch (modern)
- `git switch -c <branch>`: Create and switch to new branch (modern)
- `git merge <branch>`: Merge branch into current branch
- `git branch -d <branch>`: Delete a merged branch
- `git branch -D <branch>`: Force delete a branch
- `git branch -m <old> <new>`: Rename a branch

## Remote Operations

- `git remote -v`: List remote repositories
- `git remote add origin <url>`: Add a remote repository
- `git fetch`: Download objects from remote
- `git pull`: Fetch and merge from remote
- `git pull --rebase`: Fetch and rebase onto remote
- `git push`: Push commits to remote
- `git push -u origin <branch>`: Push and set upstream tracking
- `git push --force-with-lease`: Force update if the remote matches expectations; background fetches can weaken the default check

## Inspection & Comparison

- `git log`: Show commit history
- `git log --oneline --graph`: Compact log with branch graph
- `git log -p <file>`: Show changes over time for a file
- `git diff`: Show unstaged changes
- `git diff --staged`: Show staged changes
- `git diff <branch1>..<branch2>`: Compare two branches
- `git show <commit>`: Show details of a commit
- `git blame <file>`: Show who changed each line

## Stashing

- `git stash`: Stash current changes
- `git stash save "message"`: Stash with a description
- `git stash list`: List all stashes
- `git stash pop`: Apply and remove latest stash
- `git stash apply`: Apply latest stash without removing
- `git stash drop`: Delete latest stash
- `git stash clear`: Delete all stashes

## Undoing Changes

- `git revert <commit>`: Create new commit that undoes a commit
- `git reset --soft HEAD~1`: Undo last commit, keep changes staged
- `git reset --mixed HEAD~1`: Undo last commit, keep changes unstaged
- `git reset --hard HEAD~1`: Undo last commit and discard changes
- `git cherry-pick <commit>`: Apply a specific commit to current branch
- `git rebase <branch>`: Reapply commits on top of another branch
- `git rebase -i HEAD~3`: Interactive rebase for last 3 commits

## Sources

- `https://git-scm.com/docs`: Git reference: repository, branch, history, and remote commands.
- `https://git-scm.com/docs/git-push`: Git push: force-with-lease conditions and background-fetch limits.

## Related

- Cheatsheet: [Git History and Diffs](https://findutils.com/cheatsheets/git-history/)
- Cheatsheet: [Git Branches and Remotes](https://findutils.com/cheatsheets/git-branches-remotes/)
- Cheatsheet: [Gitignore Patterns](https://findutils.com/cheatsheets/gitignore-patterns/)
- Tool: [GitHub Dev Card](https://findutils.com/developers/github-dev-card/)
