Git Commands Cheatsheet

Searchable reference of essential Git commands with examples

gitcommandscheatsheetreferenceversion control

Showing 57 of 57 commands

CategoryCommandDescription
Setupgit initInitialize a new Git repository
Setupgit clone <url>Clone a remote repository
Setupgit config --global user.name "Name"Set global username
Setupgit config --global user.email "email"Set global email
Basicgit statusShow working tree status
Basicgit add .Stage all changes
Basicgit add <file>Stage a specific file
Basicgit commit -m "message"Commit staged changes with a message
Basicgit commit --amendModify the last commit
Basicgit logShow commit history
Basicgit log --onelineShow compact commit history
Basicgit log --graph --allShow branch graph
Basicgit diffShow unstaged changes
Basicgit diff --stagedShow staged changes
Basicgit show <commit>Show a specific commit
Branchinggit branchList local branches
Branchinggit branch <name>Create a new branch
Branchinggit branch -d <name>Delete a branch
Branchinggit branch -D <name>Force delete a branch
Branchinggit checkout <branch>Switch to a branch
Branchinggit checkout -b <branch>Create and switch to a new branch
Branchinggit switch <branch>Switch branches (modern)
Branchinggit switch -c <branch>Create and switch branches (modern)
Branchinggit merge <branch>Merge a branch into current
Branchinggit rebase <branch>Rebase current branch onto another
Branchinggit rebase -i HEAD~3Interactive rebase last 3 commits
Branchinggit cherry-pick <commit>Apply a specific commit
Remotegit remote -vShow remote connections
Remotegit remote add origin <url>Add a remote
Remotegit fetch originFetch from remote without merging
Remotegit pull origin <branch>Fetch and merge from remote
Remotegit push origin <branch>Push branch to remote
Remotegit push --force-with-leaseSafe force push
Remotegit push origin --delete <branch>Delete remote branch
Remotegit push --tagsPush all tags to remote
Stashgit stashStash current changes
Stashgit stash push -m "message"Stash with a message
Stashgit stash listList all stashes
Stashgit stash popApply and remove last stash
Stashgit stash apply stash@{0}Apply a specific stash
Stashgit stash drop stash@{0}Delete a specific stash
Undogit reset HEAD <file>Unstage a file
Undogit reset --soft HEAD~1Undo last commit, keep changes staged
Undogit reset --mixed HEAD~1Undo last commit, keep changes unstaged
Undogit reset --hard HEAD~1Undo last commit and discard changes
Undogit revert <commit>Create a new commit undoing a commit
Undogit checkout -- <file>Discard changes in a file
Undogit restore <file>Restore file (modern)
Tagsgit tagList all tags
Tagsgit tag v1.0.0Create a lightweight tag
Tagsgit tag -a v1.0.0 -m "Release"Create an annotated tag
Tagsgit push origin v1.0.0Push a tag to remote
Advancedgit bisect startStart binary search for bug
Advancedgit blame <file>Show who changed each line
Advancedgit reflogShow history of HEAD movements
Advancedgit submodule add <url>Add a submodule
Advancedgit worktree add <path>Add a linked working tree