Git Command Reference
Essential Git commands for version control - from basic to advanced
Quick Start
New Repository
git init
git add .
git commit -m "Initial commit" Clone & Contribute
git clone <url>
git checkout -b feature
git commit -am "Add feature"
git push -u origin feature Setup & Configuration
git config --global user.name "Your Name"Set your Git usernamegit config --global user.email "you@example.com"Set your Git emailgit config --listView all Git config settingsgit initInitialize a new Git repositorygit clone <url>Clone a repository from a remote URLStaging & Changes
git statusShow working tree statusgit add <file>Add file to staging areagit add .Add all changes to staginggit add -pInteractively stage changesgit reset <file>Unstage a filegit reset --hardDiscard all changes (dangerous!)git diffShow unstaged changesgit diff --stagedShow staged changesCommits & History
git commit -m "message"Commit staged changesgit commit -am "message"Stage and commit all tracked filesgit commit --amendModify the last commitgit logShow commit historygit log --onelineShow compact commit historygit log --graph --allShow visual commit graphgit show <commit>Show commit detailsBranches
git branchList all branchesgit branch <name>Create a new branchgit branch -d <name>Delete a branch (safe)git branch -D <name>Force delete a branchgit checkout <branch>Switch to a branchgit checkout -b <name>Create and switch to new branchgit switch <branch>Switch to a branch (modern)git switch -c <name>Create and switch (modern)Merge & Rebase
git merge <branch>Merge branch into current branchgit merge --no-ff <branch>Merge with commit messagegit merge --abortAbort a merge in progressgit rebase <branch>Rebase current branch onto anothergit rebase -i <commit>Interactive rebasegit rebase --abortAbort a rebase in progressRemote Repositories
git remote -vList remote repositoriesgit remote add <name> <url>Add a remote repositorygit fetchDownload remote changesgit pullFetch and merge remote changesgit pull --rebaseFetch and rebase onto remotegit pushPush commits to remotegit push -u origin <branch>Push and set upstream branchgit push --forceForce push (use with caution!)Undo & Restore
git checkout -- <file>Discard changes in filegit restore <file>Restore file (modern)git restore --staged <file>Unstage file (modern)git revert <commit>Create new commit that undoes changesgit reset HEAD~1Undo last commit, keep changesgit reset --hard HEAD~1Undo last commit, discard changesStash (Temporary Storage)
git stashSave changes temporarilygit stash save "message"Stash with a messagegit stash listList all stashesgit stash popApply and remove last stashgit stash applyApply last stash without removinggit stash dropDelete last stashgit stash clearDelete all stashesInspect & Debug
git blame <file>Show who changed each linegit grep "pattern"Search for pattern in filesgit log -S "string"Find commits that added/removed stringgit log --follow <file>Show history including renamesgit reflogShow reference log (recover lost commits)Need creative project names?
Try Flyer Designer →