Back to cheatsheets

Version Control

Git Daily Workflow Cheatsheet

Check Current State

Show changed files

Use this before and after edits to see what is modified, staged, or untracked.

Command
git status

Show the current branch

Use this to confirm you are working on the expected branch.

Command
git branch --show-current

Show recent commits

Use this to quickly inspect the latest local history.

Command
git log --oneline -5

Stage And Commit

Stage all changed files

Use this when you want to include every current file change in the next commit.

Command
git add .

Create a commit

Use this to save staged changes with a clear message.

Command
git commit -m "Describe the change"

Push Changes

Push the current branch

Use this after committing when the branch already tracks a remote branch.

Command
git push

Push a new branch for the first time

Use this when the branch does not yet exist on GitHub.

Command
git push -u origin branch-name

Branching

Create and switch to a new branch

Use this before starting isolated feature work.

Command
git switch -c feature/my-change

Switch back to main

Use this before syncing or starting a new branch from main.

Command
git switch main

Pull latest main

Use this to sync your local main branch with GitHub.

Command
git pull

Review Changes

Show unstaged changes

Use this to review edits before staging.

Command
git diff

Show a summary of changed files

Use this for a compact view of the diff size.

Command
git diff --stat

Show staged changes

Use this to review exactly what will go into the next commit.

Command
git diff --cached

Recovery

Unstage a file

Use this when you staged a file but do not want it in the next commit.

Command
git restore --staged path/to/file

Keep In Mind

  • Commit small, meaningful changes.
  • Pull before starting new work.
  • Read diffs before committing.
  • Avoid force pushing unless you know exactly why.