Git Cheat Sheet
A quick reference for the most common Git commands — from setup and staging to pushing and branching.
Setup
Run these once when setting up Git on a new machine:
git config --global user.name "Your Name"
git config --global user.email "your@email.com"Verify your configuration:
git config --listStarting a Repository
Initialize a new repo in an existing folder:
cd path/to/your/folder
git initOr clone an existing repo from GitHub:
git clone https://github.com/username/repo.gitChecking Status
git status # see what has changed in your working directory
git log # view the full commit historyStaging and Committing
git add filename # stage a specific file
git add . # stage all changes at oncegit commit -m "Your commit message here"A commit is a permanent snapshot of everything you staged. Write commit messages in the present tense and make them descriptive — "add SSH key guide" not "stuff".
Working with Remote Repos
git remote add origin https://github.com/username/repo.gitgit push -u origin main # push commits to GitHub
git pull origin main # fetch and merge remote changesN
NOTE
Use master instead of main if your branch is named master. New
repos default to main — check with git branch if unsure.
Everyday Workflow
git pull # 1. get the latest changes
# make your edits
git add . # 2. stage everything
git commit -m "describe change" # 3. commit
git push # 4. push to GitHubUseful Commands
git diff # see what changed before staging
git checkout file # undo changes to a file
git branch # list all branches
git branch newbranch # create a new branch
git checkout newbranch # switch to a branchGit Workflow at a Glance
| Step | Command | What happens |
|---|---|---|
| 1 | git add . | Files move from working directory to staging area |
| 2 | git commit -m "message" | Staging area saved as a snapshot in local repo |
| 3 | git push | Local commits uploaded to GitHub |
| 4 | git pull | Remote changes downloaded to working directory |
Quick Reference
| Command | What it does |
|---|---|
git init | Initialize a new Git repo |
git clone <url> | Download an existing repo |
git status | Show staged, unstaged, and untracked changes |
git add . | Stage all changes |
git commit -m "msg" | Save a snapshot with a message |
git push | Upload commits to remote |
git pull | Download and merge remote changes |
git log | View commit history |
git diff | See unstaged changes |
git branch | List branches |
git checkout <branch> | Switch branches |