Git Add and Commit
Stage changes and record them as commits with clear messages.
- git add
- git commit
- git amend
- git stage
- commit message
Git Add and Commit
Stage changes and record them as commits with clear messages.
Commands
| Command | What it does |
|---|---|
git status --short | Show changed/untracked files compactly |
git add <file> | Stage a specific file |
git add -p | Stage hunks interactively |
git commit -m "message" | Commit staged changes with a message |
git commit --amend --no-edit | Fold new staged changes into the last commit |
git restore --staged <file> | Unstage a file, keep working-tree changes |
Example
git status --short
git add -p
git commit -m "feat: add retry to payment client"
FAQ
What is the staging area?
An intermediate snapshot: add builds what the next commit records; uncommitted work-tree edits stay out.
When is --amend safe?
Only before pushing. Amending rewrites history, so never amend commits others already pulled.
FAQ
What is the staging area?
An intermediate snapshot: add builds what the next commit records; uncommitted work-tree edits stay out.
When is --amend safe?
Only before pushing. Amending rewrites history, so never amend commits others already pulled.
Git
Git Config Essentials
Set identity, defaults, and aliases for Git on a new machine.
Git Clone and Init
Start a repo from scratch or copy a remote repository locally.
Git Branch Basics
Create, list, rename, and delete branches for parallel work.
Git Switch and Checkout
Move between branches and restore files without losing work.