DevKit

Git Cheat Sheet

Essential Git commands for everyday development. Generate ignore files with our .gitignore Generator.

Setup & Init

git initInitialize a new repository
git clone <url>Clone a remote repository
git config --global user.name "Name"Set global username
git config --global user.email "email"Set global email

Basic Workflow

git statusShow working tree status
git add <file>Stage a file
git add .Stage all changes
git commit -m "message"Commit staged changes
git commit -am "message"Stage + commit tracked files
git diffShow unstaged changes
git diff --stagedShow staged changes

Branching

git branchList local branches
git branch <name>Create a branch
git checkout <branch>Switch to branch
git checkout -b <name>Create and switch to branch
git branch -d <name>Delete a branch (safe)
git branch -D <name>Delete a branch (force)
git merge <branch>Merge branch into current
git rebase <branch>Rebase current onto branch

Remote

git remote -vList remotes
git remote add origin <url>Add a remote
git push -u origin <branch>Push and set upstream
git pushPush to upstream
git pullFetch and merge from upstream
git fetchFetch without merging
git push origin --delete <branch>Delete remote branch

Stash

git stashStash working changes
git stash popApply and remove latest stash
git stash listList all stashes
git stash dropRemove latest stash
git stash apply stash@{n}Apply specific stash

History & Undo

git log --onelineCompact commit log
git log --graphVisual branch graph
git reset --soft HEAD~1Undo last commit (keep changes staged)
git reset --mixed HEAD~1Undo last commit (keep changes unstaged)
git reset --hard HEAD~1Undo last commit (discard changes)
git revert <commit>Create a commit that undoes a commit
git cherry-pick <commit>Apply a commit from another branch
git reflogShow all reference updates

Tags

git tag v1.0.0Create lightweight tag
git tag -a v1.0.0 -m "msg"Create annotated tag
git push origin v1.0.0Push a tag
git push origin --tagsPush all tags

Useful Combos

git log --oneline --graph --allFull visual history
git diff HEAD~3..HEADChanges in last 3 commits
git blame <file>Show who changed each line
git clean -fdRemove untracked files and dirs
git bisect start / good / badBinary search for a bug