Skip to content

Git Command Cheat Sheet

Quick reference for common Git commands. Search below or click a command to copy it.

Setup & config

  • git config --global user.name "Your Name"Set your name
  • git config --global user.email "you@example.com"Set your email
  • git initInitialize a new repo
  • git clone <url>Clone a repository

Daily workflow

  • git statusShow working tree status
  • git add .Stage all changes
  • git add <file>Stage specific file(s)
  • git commit -m "message"Commit with message
  • git commit -am "message"Stage tracked files and commit
  • git pushPush to remote
  • git pullFetch and merge from remote

Branching

  • git branchList local branches
  • git branch -aList all branches (incl. remote)
  • git branch <name>Create a new branch
  • git checkout <branch>Switch to branch
  • git checkout -b <branch>Create and switch to branch
  • git switch <branch>Switch branch (newer)
  • git switch -c <branch>Create and switch (newer)
  • git merge <branch>Merge branch into current
  • git branch -d <branch>Delete merged branch

Remote

  • git remote -vList remotes
  • git remote add origin <url>Add remote
  • git push -u origin <branch>Push and set upstream
  • git fetch originFetch from remote
  • git pull origin <branch>Pull specific branch

Stash

  • git stashStash changes
  • git stash listList stashes
  • git stash popApply and remove top stash
  • git stash applyApply top stash, keep it
  • git stash dropDrop top stash

Undo & reset

  • git restore <file>Discard changes in working tree
  • git restore --staged <file>Unstage file
  • git reset --soft HEAD~1Undo last commit, keep changes staged
  • git reset --mixed HEAD~1Undo last commit, keep changes unstaged
  • git reset --hard HEAD~1Undo last commit, discard changes

Log & history

  • git logCommit history
  • git log --onelineCompact one-line log
  • git log -pLog with patches
  • git diffUnstaged changes
  • git diff --stagedStaged changes

Other

  • git tag <tagname>Create lightweight tag
  • git tag -a <tagname> -m "message"Create annotated tag
  • git push --tagsPush all tags
  • git clean -fdRemove untracked files/dirs
  • git rebase <branch>Rebase current branch onto branch

Example

Search for push or branch to find relevant commands. Click Copy next to any command to copy it to your clipboard.

FAQ

In a terminal (command line) inside your project folder. On Windows you can use Git Bash or PowerShell; on Mac/Linux use Terminal.
They are placeholders. Replace <branch> with a real branch name, <file> with a filename, and <url> with a repository URL.

Data Transformation Tools