Git Commands Cheat Sheet
Essential Git commands for everyday development. Bookmark this page for quick reference.
| Command | Description |
git init | Initialize a new Git repository in the current directory |
git clone <url> | Clone a remote repository to your local machine |
git config --global user.name "Name" | Set your name for all repositories |
git config --global user.email "email" | Set your email for all repositories |
| Command | Description |
git status | Show the working tree status (modified, staged, untracked files) |
git add <file> | Stage a specific file for commit |
git add . | Stage all changes in the current directory |
git commit -m "message" | Create a commit with a message |
git commit -am "message" | Stage all tracked files and commit in one step |
git diff | Show unstaged changes |
git diff --staged | Show staged changes (about to be committed) |
| Command | Description |
git branch | List all local branches |
git branch <name> | Create a new branch |
git checkout <branch> | Switch to a branch |
git checkout -b <name> | Create and switch to a new branch |
git switch <branch> | Switch branches (newer Git alternative to checkout) |
git switch -c <name> | Create and switch to a new branch |
git branch -d <name> | Delete a branch (safe — won't delete unmerged changes) |
git branch -D <name> | Force delete a branch (even if unmerged) |
| Command | Description |
git merge <branch> | Merge a branch into the current branch |
git merge --abort | Abort a merge in progress |
git rebase <branch> | Rebase current branch onto another branch |
git rebase --abort | Abort a rebase in progress |
git cherry-pick <commit> | Apply a specific commit to the current branch |
| Command | Description |
git remote -v | List all remote repositories |
git remote add origin <url> | Add a remote repository |
git push origin <branch> | Push a branch to the remote |
git push -u origin <branch> | Push and set upstream tracking |
git pull | Fetch and merge changes from the remote |
git fetch | Download changes from the remote without merging |
git fetch --prune | Fetch and remove deleted remote branches |
| Command | Description |
git stash | Temporarily save uncommitted changes |
git stash pop | Apply the most recent stash and remove it from the list |
git stash list | List all stashes |
git stash drop | Delete the most recent stash |
git stash apply stash@{n} | Apply a specific stash without removing it |
| Command | Description |
git log | Show commit history |
git log --oneline | Show compact commit history (one line per commit) |
git log --graph --oneline | Show commit history as a graph |
git show <commit> | Show details of a specific commit |
git blame <file> | Show who changed each line of a file |
git reflog | Show history of HEAD movements (useful for recovery) |
| Command | Description |
git restore <file> | Discard changes in a working file |
git restore --staged <file> | Unstage a file (keep changes in working directory) |
git reset HEAD~1 | Undo the last commit (keep changes staged) |
git reset --hard HEAD~1 | Undo the last commit and discard all changes |
git revert <commit> | Create a new commit that undoes a previous commit |
git clean -fd | Remove untracked files and directories |
| Command | Description |
git tag | List all tags |
git tag v1.0.0 | Create a lightweight tag |
git tag -a v1.0.0 -m "msg" | Create an annotated tag with a message |
git push --tags | Push all tags to the remote |