Essential Git Commands
The daily-driver Git command set for Rust teams - clone to commit to push, plus inspection commands that make debugging history fast.
Search across all documentation pages
The daily-driver Git command set for Rust teams - clone to commit to push, plus inspection commands that make debugging history fast.
git status -sb
git diff
git add Cargo.toml Cargo.lock src/
git commit -m "feat(api): add health route [API-42]"
git push -u origin feat/api-42-healthWhen to reach for this:
maingit clone git@github.com:acme/billing-api.git
cd billing-api
git config user.name "Ada Lovelace"
git config user.email "ada@acme.com"
git checkout main
git pull --rebase origin main
git checkout -b feat/api-42-health
# ... edit Rust files ...
cargo test -q
git add Cargo.toml Cargo.lock src/routes/health.rs
git commit -m "feat(api): add health route [API-42]"
git fetch origin
git rebase origin/main
git push -u origin feat/api-42-healthWhat this demonstrates:
status -sb for branch and staged summaryCargo.lock committed with dependency changes for binaries| Task | Command |
|---|---|
| What changed? | git status, git diff, git diff --staged |
| History | git log --oneline -20, git log -p src/lib.rs |
| Undo staging | git restore --staged file.rs |
| Discard edits | git restore file.rs |
| Stash WIP | git stash push -m "wip health" |
| Update branch | git pull --rebase origin main |
git blame src/error.rs
git log -S "AppError" --oneline -- src/git add . catches secrets - .env slips into commits. Fix: .gitignore plus git add -p.cargo build --locked fails. Fix: commit Cargo.lock for applications.pull --rebase on private branches.--force-with-lease only on your feat/* before review.target/ directory. Fix: global gitignore for Rust build artifacts.| Alternative | Use When | Don't Use When |
|---|---|---|
| GitHub Desktop | Visual diff preference | Scripting workflows |
jj (Jujutsu) | Experimenting with VCS | Team standard is Git CLI |
gh pr create | PR from terminal | GitHub CLI not installed |
Rebase onto main for clean PR history on private branches; merge on shared release branches per team policy.
git reset --soft HEAD~1 moves HEAD back one commit keeping staged files.
git diff origin/main...HEAD shows PR delta three-dot style.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Reviewed by Chris St. John·Last updated Jul 16, 2026