Git Commands Cheat Sheet: The Commands You’ll Use Every Day

Git Commands Cheat Sheet: The Commands You’ll Use Every Day

A no-frills reference for the common git commands that come up in day-to-day work, grouped by what you’re trying to do. Copy it and then paste it into your console. Anywhere is says <something> in the git command list, these are just placeholders. Replace them with your own command (file, url, etc.) including replacing the < and >

Setup: Starting or joining a project

Starting a new repository:

git init

Download a copy of an existing remote repository:

git clone <url>

Set the name to attach to your git commits:

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

Set the email address to attach to your git commits:

git config --global user.email "your@domain.com"

Basic Everyday Tasks

See what’s changed, staged, or tracked in the codebase

git status

See what’s changed, staged, or tracked in the codebase

git status

Stage every changed file in the current folder:

git add .

Stage a specific file

git add <file>

Save staged changes as a commit with a message

git commit -m "Your message"

Show all unstaged changes line by line

git diff

Local Branching

List all the local branches

git branch

Create a new branch and switch to it

git switch -c <new-branch-name>

Switch to an existing branch

git switch <branch-name>

Merge a branch into your current branch

git merge <branch-name>

Remotes

Fetch and merge the latest changes from the remote:

git pull

Upload your committed changes

git push

Push a new branch and link it to the remote

git push -u origin <branch>

List all remotes that this repository is connected to:

git remote -v

Reviewing The Repo History

Show a compact view of the commit history

git log --oneline --graph

See exactly what was changed during a specific commit:

git show <commit>

See who last made a change to a specific file:

git blame <file>

Undoing Things

Discard uncommitted changes to a file:

git restore <file>

Undo to last commit but keep the changes that are staged:

git reset --soft HEAD~1

Create a commit that undoes an earlier commit

git revert <commit>

Shelve your uncommitted changes so you can switch context:

git stash

About Katherine Wyers

I'm a software engineer specialising in identity data in digital public infrastructures. I have a PhD in information systems and an MSc in software engineering

<-- See All Blog Articles