UtilityBelt

Git Cheatsheet

Common Git commands for daily development workflow.

Configuration

CommandDescription
git config --global user.name "Name"Set your name globally
git config --global user.email "email"Set your email globally
git config --global alias.<name> <command>Create a Git alias
git config --listList all configuration settings

Getting Started

CommandDescription
git initInitialize a new Git repository
git clone <url>Clone an existing repository
git clone <url> <dir>Clone into a specific directory

Basic Workflow

CommandDescription
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"Add and commit in one step (tracked files)
git rm <file>Remove a file from tracking
git mv <old> <new>Rename a tracked file

Branching & Merging

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

Remote Repositories

CommandDescription
git remote -vList remote repositories
git remote add <name> <url>Add a remote
git push <remote> <branch>Push commits to a remote
git push -u <remote> <branch>Push and set upstream
git pullFetch and merge from upstream
git fetchFetch changes without merging
git remote remove <name>Remove a remote

Inspection & History

CommandDescription
git logShow commit history
git log --onelineCompact commit history
git log --graphShow commit history as a graph
git diffShow unstaged changes
git diff --stagedShow staged changes
git show <commit>Show details of a specific commit
git blame <file>Show who changed each line

Undoing Changes

CommandDescription
git checkout -- <file>Discard unstaged changes
git reset <file>Unstage a file
git reset --soft HEAD~1Undo last commit, keep changes staged
git reset --hard HEAD~1Undo last commit, discard changes
git revert <commit>Create a new commit that undoes a previous one
git stashStash working directory changes
git stash popApply and remove the latest stash
git stash listList stashes

Tagging

CommandDescription
git tagList tags
git tag <name>Create a lightweight tag
git tag -a <name> -m "msg"Create an annotated tag
git push --tagsPush tags to remote