Skip to content
AI Stack Nest
2 min read · updated 18 Nov 2026

Git Basics Cheat Sheet

The most common Git commands for tracking changes, branching, and working with remotes

Setup

CommandWhat it does
git config --global user.name "Name"Sets your name for all commits
git config --global user.email "you@example.com"Sets your email for all commits
git config --listShows your current configuration

Starting a Repository

CommandWhat it does
git initCreates a new repo in the current folder
git clone <url>Copies a remote repo to your machine

Checking State

CommandWhat it does
git statusShows changed, staged, and untracked files
git diffShows unstaged changes line by line
git diff --stagedShows staged changes ready to commit
git logShows the commit history
git log --onelineShows history one line per commit

Staging and Committing

CommandWhat it does
git add <file>Stages a specific file
git add .Stages all changes in the current folder
git commit -m "message"Commits staged changes with a message
git commit --amendEdits the last commit (before pushing)

Undoing Changes

CommandWhat it does
git restore <file>Discards unstaged changes in a file
git restore --staged <file>Unstages a file without losing changes
git revert <commit>Creates a new commit that undoes a previous one
git reset --soft HEAD~1Undoes last commit, keeps changes staged

Branches

CommandWhat it does
git branchLists all local branches
git branch <name>Creates a new branch
git switch <name>Switches to a branch
git switch -c <name>Creates and switches to a new branch
git merge <branch>Merges a branch into the current one
git branch -d <name>Deletes a branch (safe, only if merged)

Working with Remotes

CommandWhat it does
git remote -vLists remote connections
git remote add origin <url>Adds a remote called origin
git push origin <branch>Pushes branch to remote
git push -u origin <branch>Pushes and sets upstream tracking
git pullFetches and merges remote changes
git fetchDownloads remote changes without merging

Stashing

CommandWhat it does
git stashSaves uncommitted changes temporarily
git stash popRestores the most recent stash
git stash listLists all stashes

Quick Workflow Reference

# Start a feature
git switch -c my-feature

# Make changes, then:
git add .
git commit -m "Add my feature"

# Merge back to main
git switch main
git merge my-feature
git push origin main

More cheat sheets

Not sure your computer can run a model? Use the will-it-run checker.