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 username
git config --global user.email "you@example.com"Set your Git email
git config --listView all Git config settings
git initInitialize a new Git repository
git clone <url>Clone a repository from a remote URL

Staging & Changes

git statusShow working tree status
git add <file>Add file to staging area
git add .Add all changes to staging
git add -pInteractively stage changes
git reset <file>Unstage a file
git reset --hardDiscard all changes (dangerous!)
git diffShow unstaged changes
git diff --stagedShow staged changes

Commits & History

git commit -m "message"Commit staged changes
git commit -am "message"Stage and commit all tracked files
git commit --amendModify the last commit
git logShow commit history
git log --onelineShow compact commit history
git log --graph --allShow visual commit graph
git show <commit>Show commit details

Branches

git branchList all branches
git branch <name>Create a new branch
git branch -d <name>Delete a branch (safe)
git branch -D <name>Force delete a branch
git checkout <branch>Switch to a branch
git checkout -b <name>Create and switch to new branch
git switch <branch>Switch to a branch (modern)
git switch -c <name>Create and switch (modern)

Merge & Rebase

git merge <branch>Merge branch into current branch
git merge --no-ff <branch>Merge with commit message
git merge --abortAbort a merge in progress
git rebase <branch>Rebase current branch onto another
git rebase -i <commit>Interactive rebase
git rebase --abortAbort a rebase in progress

Remote Repositories

git remote -vList remote repositories
git remote add <name> <url>Add a remote repository
git fetchDownload remote changes
git pullFetch and merge remote changes
git pull --rebaseFetch and rebase onto remote
git pushPush commits to remote
git push -u origin <branch>Push and set upstream branch
git push --forceForce push (use with caution!)

Undo & Restore

git checkout -- <file>Discard changes in file
git restore <file>Restore file (modern)
git restore --staged <file>Unstage file (modern)
git revert <commit>Create new commit that undoes changes
git reset HEAD~1Undo last commit, keep changes
git reset --hard HEAD~1Undo last commit, discard changes

Stash (Temporary Storage)

git stashSave changes temporarily
git stash save "message"Stash with a message
git stash listList all stashes
git stash popApply and remove last stash
git stash applyApply last stash without removing
git stash dropDelete last stash
git stash clearDelete all stashes

Inspect & Debug

git blame <file>Show who changed each line
git grep "pattern"Search for pattern in files
git log -S "string"Find commits that added/removed string
git log --follow <file>Show history including renames
git reflogShow reference log (recover lost commits)

Need creative project names?

Try Flyer Designer →