💻 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 usernamegit config --global user.email "[email]"Set your emailgit config --listList all config settingsgit initInitialize a new repositorygit clone [url]Clone a repositoryBasic Snapshotting
git statusShow working tree statusgit add [file]Add file to staging areagit add .Add all changes to staginggit add -pInteractively stage hunksgit commit -m "[message]"Commit with messagegit commit -am "[message]"Add and commit tracked filesgit commit --amendAmend the last commitgit diffShow unstaged changesgit diff --stagedShow staged changesgit reset [file]Unstage a filegit reset --hardDiscard all local changesgit checkout -- [file]Discard changes in fileBranching & Merging
git branchList local branchesgit branch -aList all branchesgit branch [name]Create a new branchgit branch -d [name]Delete a branchgit branch -D [name]Force delete a branchgit checkout [branch]Switch to a branchgit checkout -b [branch]Create and switch to branchgit switch [branch]Switch to a branch (newer)git switch -c [branch]Create and switch (newer)git merge [branch]Merge branch into currentgit merge --no-ff [branch]Merge with merge commitgit rebase [branch]Rebase onto branchgit rebase -i HEAD~[n]Interactive rebase last n commitsgit cherry-pick [commit]Apply a specific commitRemote Repositories
git remote -vList remote repositoriesgit remote add [name] [url]Add a remotegit remote remove [name]Remove a remotegit fetchFetch from remotegit fetch --allFetch from all remotesgit pullFetch and mergegit pull --rebaseFetch and rebasegit pushPush to remotegit push -u origin [branch]Push and set upstreamgit push --forceForce push (dangerous!)git push --force-with-leaseSafer force pushInspection & History
git logShow commit historygit log --onelineCompact commit historygit log --graphShow branch graphgit log -p [file]Show file change historygit log --author="[name]"Filter by authorgit show [commit]Show commit detailsgit blame [file]Show who changed each linegit reflogShow reference logStashing
git stashStash changesgit stash save "[message]"Stash with messagegit stash listList stashesgit stash popApply and remove stashgit stash applyApply stash (keep it)git stash dropDelete most recent stashgit stash clearDelete all stashesTagging
git tagList tagsgit tag [name]Create lightweight taggit tag -a [name] -m "[msg]"Create annotated taggit push --tagsPush all tagsgit tag -d [name]Delete local tagUndoing Changes
git revert [commit]Create commit that undoesgit reset --soft HEAD~1Undo commit, keep changes stagedgit reset --mixed HEAD~1Undo commit, keep changesgit reset --hard HEAD~1Undo commit, discard changesgit clean -fdRemove untracked files/dirsgit restore [file]Restore file (newer)git restore --staged [file]Unstage file (newer)