Git Cheatsheet
A comprehensive reference of commonly used Git commands and keyboard shortcuts to boost your productivity.
| Command | Description | Example | Note |
|---|---|---|---|
git init | Initialize a new Git repository | git init my-project | Creates a new .git subdirectory in the current directory |
git clone | Clone a repository into a new directory | git clone https://github.com/username/repository.git | Clone the repository to your local machine |
git add | Add file contents to the index | git add filename.js | Use "git add ." to add all changes |
git commit | Record changes to the repository | git commit -m "Add new feature" | Use -a flag to commit all tracked files |
git status | Show the working tree status | git status | Shows modified files in working directory |
git diff | Show changes between commits, commit and working tree, etc | git diff | Use git diff --staged to see staged changes |
git log | Show commit logs | git log --oneline | Shows the commit history |
git branch | List, create, or delete branches | git branch feature-branch | Use -d flag to delete a branch |
git checkout | Switch branches or restore working tree files | git checkout feature-branch | Use -b flag to create a new branch and switch to it |
git switch | Switch branches (newer alternative to checkout) | git switch feature-branch | Use -c flag to create a new branch and switch to it |
git merge | Join two or more development histories together | git merge feature-branch | Merges the specified branch into the current branch |
git rebase | Reapply commits on top of another base tip | git rebase main | Rewrites commit history to create a linear history |
git tag | Create, list, delete or verify a tag object | git tag v1.0.0 | Use -a for annotated tags with messages |
git remote | Manage set of tracked repositories | git remote -v | Lists all remote connections |
git fetch | Download objects and refs from another repository | git fetch origin | Fetches changes but doesn't integrate them |
git pull | Fetch from and integrate with another repository | git pull origin main | Combination of git fetch and git merge |
git push | Update remote refs along with associated objects | git push origin main | Push local commits to the remote repository |
git show | Show various types of objects | git show commit-hash | Shows the commit data and diffs |
git blame | Show what revision last modified each line of a file | git blame filename.js | Shows who changed what and when in a file |
git grep | Print lines matching a pattern | git grep "function" | Search for specific strings in tracked files |
git diff-tree | Compare content and mode of blobs in trees | git diff-tree HEAD HEAD~1 | Shows all changes between two commit points |
git restore | Restore working tree files | git restore filename.js | Modern replacement for git checkout to undo changes |
git reset | Reset current HEAD to the specified state | git reset HEAD~1 | Use --soft to keep changes, --hard to discard changes |
git revert | Create a new commit that undoes previous changes | git revert commit-hash | Safer than reset for shared branches |
git clean | Remove untracked files from the working tree | git clean -fd | Use -n flag to see what would be removed |
git stash | Stash changes in a dirty working directory | git stash save "WIP: feature" | Use git stash pop to apply and remove the stash |
git cherry-pick | Apply changes from existing commits | git cherry-pick commit-hash | Applies the changes from specific commits to current branch |
git bisect | Use binary search to find a commit that introduced a bug | git bisect start
git bisect bad
git bisect good commit-hash | Helps locate which commit caused a bug |
git worktree | Manage multiple working trees attached to the same repository | git worktree add ../path branch-name | Create a linked working copy to work on multiple branches |
git submodule | Initialize, update or inspect submodules | git submodule add https://github.com/username/repo.git | Include other Git repositories within your repository |
git reflog | Manage reflog information | git reflog | Shows a log of changes to the HEAD in local repository |
Git Keyboard Shortcuts
These keyboard shortcuts work in various Git environments and can boost your productivity.
| Shortcut | Description |
|---|---|
| Tab | Autocomplete Git commands, branch names, and file paths |
| Ctrl + R | Search through command history |
| ↑ / ↓ | Navigate through previously used commands |
| Ctrl + L | Clear the terminal screen |
| Ctrl + C | Cancel current command or operation |
| q | Exit from log, diff, or help pages |
Git Pro Tips
Custom Git Configuration
Setup global .gitconfig for personalized experience:
[user]
name = Your Name
email = [email protected]
[core]
editor = code --wait
autocrlf = input
[color]
ui = auto
[pull]
rebase = trueCreating a global .gitignore
Ignore files system-wide rather than in each project:
# Create global gitignore
touch ~/.gitignore_global
# Add common files to ignore
echo ".DS_Store
node_modules/
.vscode/
*.log
.env" >> ~/.gitignore_global
# Set it in git config
git config --global core.excludesfile ~/.gitignore_globalRelated Tools
You might also find these useful

Jupyter Notebook Markdown Cheat Sheet
Master Jupyter Notebook Markdown syntax with this comprehensive cheat sheet. Learn LaTeX math formulas, code blocks, tables, MyST extensions, and advanced formatting techniques for data science documentation. Perfect for Python developers, data scientists, and researchers working with Jupyter notebooks.

JSON XML Converter
Convert JSON to XML format easily. Transform data between these popular formats with this free online tool.

JSON TOML Converter
Convert JSON to TOML format easily. Transform data between these popular formats with this free online tool.

JSON Formatter
Format and beautify JSON with customizable indentation. Supports JSON5, comments, trailing commas and advanced formatting options.

String to Slug
Convert a string to a slug.

Shrug Emoji Generator
Generate shrug emoji ¯_(ツ)_/¯ in different fonts and styles.