Git Cheat Sheet

Comprehensive Git workflow reference guide

Git Cheat Sheet

Comprehensive reference guide for Git workflows and commands. Click the copy button to copy any command.

123
Total Commands
123
Filtered Results

Setup and Configuration

CommandCopyDescription
git config --global user.name "Your Name"Set your name
git config --global user.email "email@example.com"Set your email
git config --global color.ui trueEnable colorization
git config --global core.editor "vim"Set default editor
git config --listList all configuration
git config --global alias.co checkoutCreate alias for checkout
git config --global alias.br branchCreate alias for branch
git config --global alias.st statusCreate alias for status

Creating Repositories

CommandCopyDescription
git initInitialize new repository
git init <directory>Initialize repository in directory
git clone <url>Clone repository
git clone <url> <directory>Clone to specific directory
git clone --depth 1 <url>Shallow clone (latest commit only)

Basic Workflow

CommandCopyDescription
git statusCheck status of files
git status -sShort status
git add <file>Stage specific file
git add .Stage all changes
git add -AStage all (including deletions)
git add -pInteractive staging
git diffShow unstaged changes
git diff --stagedShow staged changes
git diff HEADShow all changes
git commit -m "message"Commit with message
git commit -am "message"Stage and commit all
git commit --amendAmend last commit
git commit --amend --no-editAmend without changing message

Branching

CommandCopyDescription
git branchList all local branches
git branch -aList all branches (local and remote)
git branch -rList remote branches
git branch <name>Create new branch
git branch -d <name>Delete branch
git branch -D <name>Force delete branch
git branch -m <old> <new>Rename branch
git checkout <branch>Switch to branch
git checkout -b <branch>Create and switch to branch
git checkout -Switch to previous branch
git switch <branch>Switch branches (modern)
git switch -c <branch>Create and switch (modern)

Merging

CommandCopyDescription
git merge <branch>Merge branch into current
git merge --no-ff <branch>Merge with merge commit
git merge --squash <branch>Squash and merge
git merge --abortAbort merge
git mergetoolOpen merge tool

Remote Repositories

CommandCopyDescription
git remoteList remotes
git remote -vList remotes with URLs
git remote add <name> <url>Add remote
git remote remove <name>Remove remote
git remote rename <old> <new>Rename remote
git remote show <name>Show remote info
git fetchFetch from all remotes
git fetch <remote>Fetch from specific remote
git fetch --pruneFetch and remove deleted branches
git pullFetch and merge
git pull --rebaseFetch and rebase
git pushPush to remote
git push <remote> <branch>Push branch to remote
git push -u origin <branch>Push and set upstream
git push --allPush all branches
git push --tagsPush all tags
git push --forceForce push (dangerous)
git push --force-with-leaseSafer force push

History and Logs

CommandCopyDescription
git logShow commit history
git log --onelineCondensed history
git log --graphShow graph
git log --graph --oneline --allVisual branch history
git log -n 5Show last 5 commits
git log --author="name"Filter by author
git log --since="2 weeks ago"Filter by date
git log --follow <file>Show file history
git log -pShow changes in commits
git show <commit>Show commit details
git show <commit>:<file>Show file at commit
git blame <file>Show who changed each line

Undoing Changes

CommandCopyDescription
git checkout -- <file>Discard changes in file
git restore <file>Restore file (modern)
git restore --staged <file>Unstage file
git reset <file>Unstage file
git reset --soft HEAD~1Undo commit, keep changes staged
git reset HEAD~1Undo commit, keep changes unstaged
git reset --hard HEAD~1Undo commit, discard changes
git reset --hard origin/mainReset to remote state
git revert <commit>Create new commit to undo
git revert HEADRevert last commit
git clean -fdRemove untracked files/directories
git clean -fdnDry run of clean

Stashing

CommandCopyDescription
git stashStash changes
git stash save "message"Stash with message
git stash -uStash including untracked
git stash listList stashes
git stash showShow latest stash
git stash show -pShow stash diff
git stash popApply and remove stash
git stash applyApply stash
git stash apply stash@{2}Apply specific stash
git stash dropDelete stash
git stash clearDelete all stashes
git stash branch <branch>Create branch from stash

Tagging

CommandCopyDescription
git tagList tags
git tag <name>Create lightweight tag
git tag -a <name> -m "message"Create annotated tag
git tag <name> <commit>Tag specific commit
git tag -d <name>Delete local tag
git push origin <tag>Push tag
git push origin --tagsPush all tags
git push origin :refs/tags/<tag>Delete remote tag

Rebasing

CommandCopyDescription
git rebase <branch>Rebase onto branch
git rebase -i HEAD~3Interactive rebase last 3 commits
git rebase --continueContinue after resolving conflicts
git rebase --skipSkip current commit
git rebase --abortAbort rebase
git rebase origin/mainRebase on remote main

Cherry-picking

CommandCopyDescription
git cherry-pick <commit>Apply commit to current branch
git cherry-pick <commit1> <commit2>Cherry-pick multiple commits
git cherry-pick --continueContinue cherry-pick
git cherry-pick --abortAbort cherry-pick

Advanced

CommandCopyDescription
git reflogShow reference logs
git bisect startStart binary search
git bisect goodMark commit as good
git bisect badMark commit as bad
git bisect resetEnd bisect session
git worktree add <path> <branch>Create linked working tree
git worktree listList working trees
git worktree remove <path>Remove working tree

All operations are performed locally in your browser. No data is sent to any server.

About Git Cheat Sheet

This section will contain detailed, SEO-friendly content about the Git Cheat Sheet.

In the future, this content will be managed through a headless CMS, allowing you to:

  • Add detailed explanations about how to use this tool
  • Include examples and use cases
  • Provide tips and best practices
  • Add FAQs and troubleshooting guides
  • Update content without touching the code

How to Use

Step-by-step instructions for using the Git Cheat Sheet will appear here. This content will be fully customizable through the admin panel.

Features

Key features and benefits of this tool will be listed here. All content is editable via the CMS.