📚💻 Development

Git Cheatsheet

Common Git commands reference

Git commands cheatsheet with common operations. Quick reference for git clone, commit, push, pull, branch, merge, and more. Free Git guide.

Setup & Config

git config --global user.name "[name]"Set your username
git config --global user.email "[email]"Set your email
git config --listList all config settings
git initInitialize a new repository
git clone [url]Clone a repository

Basic Snapshotting

git statusShow working tree status
git add [file]Add file to staging area
git add .Add all changes to staging
git add -pInteractively stage hunks
git commit -m "[message]"Commit with message
git commit -am "[message]"Add and commit tracked files
git commit --amendAmend the last commit
git diffShow unstaged changes
git diff --stagedShow staged changes
git reset [file]Unstage a file
git reset --hardDiscard all local changes
git checkout -- [file]Discard changes in file

Branching & Merging

git branchList local branches
git branch -aList all branches
git branch [name]Create a new branch
git branch -d [name]Delete a branch
git branch -D [name]Force delete a branch
git checkout [branch]Switch to a branch
git checkout -b [branch]Create and switch to branch
git switch [branch]Switch to a branch (newer)
git switch -c [branch]Create and switch (newer)
git merge [branch]Merge branch into current
git merge --no-ff [branch]Merge with merge commit
git rebase [branch]Rebase onto branch
git rebase -i HEAD~[n]Interactive rebase last n commits
git cherry-pick [commit]Apply a specific commit

Remote Repositories

git remote -vList remote repositories
git remote add [name] [url]Add a remote
git remote remove [name]Remove a remote
git fetchFetch from remote
git fetch --allFetch from all remotes
git pullFetch and merge
git pull --rebaseFetch and rebase
git pushPush to remote
git push -u origin [branch]Push and set upstream
git push --forceForce push (dangerous!)
git push --force-with-leaseSafer force push

Inspection & History

git logShow commit history
git log --onelineCompact commit history
git log --graphShow branch graph
git log -p [file]Show file change history
git log --author="[name]"Filter by author
git show [commit]Show commit details
git blame [file]Show who changed each line
git reflogShow reference log

Stashing

git stashStash changes
git stash save "[message]"Stash with message
git stash listList stashes
git stash popApply and remove stash
git stash applyApply stash (keep it)
git stash dropDelete most recent stash
git stash clearDelete all stashes

Tagging

git tagList tags
git tag [name]Create lightweight tag
git tag -a [name] -m "[msg]"Create annotated tag
git push --tagsPush all tags
git tag -d [name]Delete local tag

Undoing Changes

git revert [commit]Create commit that undoes
git reset --soft HEAD~1Undo commit, keep changes staged
git reset --mixed HEAD~1Undo commit, keep changes
git reset --hard HEAD~1Undo commit, discard changes
git clean -fdRemove untracked files/dirs
git restore [file]Restore file (newer)
git restore --staged [file]Unstage file (newer)