Lantern Quay · Engineering · Rev. 2026-11-09

Git: the everyday commands

The 46 commands we reach for most weeks, grouped by what you're trying to do. Kept by Tomasz Wrobel for new starters. It's for looking things up on screen, so keep it open in a tab and use the filter. Anything in <angle brackets> is a value you supply: type it without the brackets.

46 of 46 / to type, Esc to clear

01Set up, once

  • git config --global user.name "Your Name"

    Sets the name recorded on every commit you make.

  • git config --global user.email "you@example.com"

    Sets the email recorded on every commit you make.

  • git clone <url>

    Copies a repository and its whole history into a new folder.

  • git init

    Starts a new repository in the current folder.

02See where you are

  • git status

    Shows your branch and which files are changed, staged or untracked.

  • git diff

    Shows the changes you haven't staged yet, line by line.

  • git diff --staged

    Shows what is staged, which is what the next commit will contain.

  • git log --oneline

    Lists commits one per line, newest first.

  • git log --oneline --graph --all

    Draws every branch's history as a text graph.

  • git show <commit>

    Shows one commit: its message, its author and its changes.

  • git blame <file>

    Shows which commit and author last changed each line.

03Save your work

  • git add <file>

    Stages that file's changes for the next commit.

  • git add -p

    Walks through your changes one chunk at a time and asks which to stage.

  • git add .

    Stages everything changed in the current folder and below, new files included.

  • git commit -m "message"

    Records what's staged as a new commit with that message.

  • git commit --amend

    Replaces your last commit with one that adds what's staged, and lets you reword the message. only before you push

  • git stash

    Shelves uncommitted changes to tracked files and gives you a clean working tree.

  • git stash pop

    Puts the most recent stash back and removes it from the stash list.

04Branch and merge

  • git branch

    Lists local branches, with a star on the one you're on.

  • git switch <branch>

    Moves you to an existing branch.

  • git switch -c <branch>

    Creates a new branch from where you are and moves you onto it.

  • git merge <branch>

    Brings that branch's commits into the branch you're on.

  • git rebase main

    Replays your branch's commits on top of your local main. They get new IDs.

  • git cherry-pick <commit>

    Copies one commit from anywhere onto your current branch.

  • git branch -d <branch>

    Deletes a local branch. Refuses if its work isn't merged.

05Sync with the remote

  • git remote -v

    Lists the remotes and the URLs they point to.

  • git fetch

    Downloads new commits from the remote without touching your files.

  • git pull

    Fetches, then brings the remote branch's new commits into yours.

  • git pull --rebase

    Fetches, then replays your unpushed commits on top of the remote's.

  • git push

    Sends your branch's new commits to its upstream branch.

  • git push -u origin <branch>

    The first push of a new branch. Sets its upstream, so a plain git push works from then on.

  • git push --force-with-lease

    Overwrites the remote branch with yours, but refuses if someone has pushed since your last fetch. your own branches only

06Undo

  • git restore <file>

    Throws away your unstaged changes to that file. can't be undone

  • git restore --staged <file>

    Unstages the file and keeps your changes.

  • git revert <commit>

    Adds a new commit that reverses an earlier one. Safe on shared branches.

  • git reset --soft HEAD~1

    Removes the last commit and leaves its changes staged.

  • git reset --hard HEAD~1

    Removes the last commit and discards its changes, along with any other uncommitted changes to tracked files. uncommitted work is gone for good

  • git reflog

    Lists where HEAD has pointed recently, so you can find a commit you thought was lost.

07When a merge or rebase conflicts

Edit each file between the <<<<<<< and >>>>>>> markers, git add it, then:

  • git merge --continue

    Finishes the merge once every conflict is fixed and staged.

  • git merge --abort

    Gives up on the merge and puts everything back as it was.

  • git rebase --continue

    Carries on with the rebase after you fix and stage a conflict.

  • git rebase --abort

    Gives up on the rebase and puts your branch back as it was.

08Find things

  • git grep "text"

    Searches the tracked files in the current folder and below for that text.

  • git log -S "text"

    Lists the commits that added or removed that text.

  • git log -- <file>

    Lists the commits that changed that file.

  • git log --author="name"

    Lists the commits made by that author.

Words you'll see
HEAD
The commit you have checked out right now.
HEAD~1
The commit just before that one.
origin
The default name for the remote you cloned from.
upstream
The remote branch your branch pushes to and pulls from.
staged
Marked to go into the next commit.
working tree
The files as they are on your disk.
Versions

This sheet needs Git 2.23 or newer. Check yours with git --version. Older guides use git checkout where this one uses switch and restore.