Git Commands Cheat Sheet

Essential Git commands reference guide

Git Commands Cheat Sheet

Quick reference guide for Git version control commands. Click the copy button to copy any command.

87
Total Commands
87
Filtered Results

Setup and Config

CommandCopyDescription
git config --global user.name "name"Set your name for commits
git config --global user.email "email"Set your email for commits
git config --listList all Git configuration
git config --global --editEdit global config file
git config --global core.editor "code"Set default editor

Creating Repositories

CommandCopyDescription
git initInitialize new Git repository
git clone <url>Clone remote repository
git clone <url> <directory>Clone to specific directory

Basic Snapshotting

CommandCopyDescription
git statusShow working tree status
git add <file>Stage specific file
git add .Stage all changes
git add -AStage all changes (including deletions)
git add -pInteractively stage changes
git commit -m "message"Commit staged changes
git commit -am "message"Stage and commit all changes
git commit --amendAmend last commit
git reset <file>Unstage file
git reset --hardDiscard all changes
git reset --soft HEAD~1Undo last commit, keep changes
git rm <file>Remove file and stage deletion
git mv <old> <new>Move or rename file

Branching and Merging

CommandCopyDescription
git branchList all branches
git branch <name>Create new branch
git branch -d <name>Delete branch
git branch -D <name>Force delete branch
git branch -m <new-name>Rename current branch
git checkout <branch>Switch to branch
git checkout -b <branch>Create and switch to new branch
git switch <branch>Switch to branch (modern)
git switch -c <branch>Create and switch to new branch (modern)
git merge <branch>Merge branch into current branch
git merge --no-ff <branch>Merge with merge commit
git merge --abortAbort merge

Remote Repositories

CommandCopyDescription
git remoteList remote repositories
git remote -vList remotes with URLs
git remote add <name> <url>Add remote repository
git remote remove <name>Remove remote
git remote rename <old> <new>Rename remote
git fetchFetch from remote
git fetch <remote>Fetch from specific remote
git pullFetch and merge from remote
git pull --rebaseFetch and rebase on remote
git pushPush to remote
git push <remote> <branch>Push branch to remote
git push -u origin <branch>Push and set upstream
git push --forceForce push (use with caution)
git push --tagsPush all tags

Inspection and Comparison

CommandCopyDescription
git logShow commit history
git log --onelineShow condensed commit history
git log --graphShow commit history with graph
git log --all --decorate --oneline --graphShow detailed graph (dog)
git log -n <number>Show last n commits
git log --author="name"Show commits by author
git log --since="2 weeks ago"Show commits since date
git show <commit>Show commit details
git diffShow unstaged changes
git diff --stagedShow staged changes
git diff <branch1> <branch2>Compare two branches
git blame <file>Show who changed each line

Stashing

CommandCopyDescription
git stashStash current changes
git stash save "message"Stash with message
git stash listList all stashes
git stash popApply and remove last stash
git stash applyApply last stash
git stash dropDelete last stash
git stash clearDelete all stashes

Tagging

CommandCopyDescription
git tagList all tags
git tag <name>Create lightweight tag
git tag -a <name> -m "message"Create annotated tag
git tag -d <name>Delete tag
git push origin <tag>Push tag to remote

Undoing Changes

CommandCopyDescription
git checkout -- <file>Discard changes in file
git restore <file>Discard changes in file (modern)
git restore --staged <file>Unstage file (modern)
git revert <commit>Revert commit with new commit
git reset HEAD~1Undo last commit, keep changes
git reset --hard HEAD~1Undo last commit, discard changes

Rebasing

CommandCopyDescription
git rebase <branch>Rebase onto branch
git rebase --continueContinue rebase after resolving conflicts
git rebase --abortAbort rebase
git rebase -i HEAD~3Interactive rebase last 3 commits

Advanced

CommandCopyDescription
git cherry-pick <commit>Apply commit to current branch
git clean -fdRemove untracked files and directories
git reflogShow reference logs
git bisect startStart binary search for bug
git submodule add <url>Add submodule
git submodule update --initInitialize submodules

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

About Git Commands Cheat Sheet

This section will contain detailed, SEO-friendly content about the Git Commands 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 Commands 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.