Git Version Control
You can perform git operations using the shell tool. Use git for version control tasks like committing, branching, diffing, and managing repositories.
Common Operations
Status and History
git status
git log --oneline -20
git diff
git diff --staged
git show HEAD
Branching
git branch # list branches
git branch feature-name # create branch
git checkout feature-name # switch branch
git checkout -b feature-name # create and switch
git merge feature-name # merge branch
Committing
git add <files> # stage specific files
git commit -m "message" # commit with message
git commit --amend # amend last commit
Remote Operations
git pull origin main
git push origin branch-name
git fetch origin
git remote -v
Stash
git stash # stash changes
git stash list # list stashes
git stash pop # apply and drop
Investigation
git log --oneline --graph --all -20 # visual branch history
git blame <file> # line-by-line authorship
git log --follow -p -- <file> # file history with diffs
git reflog # recent HEAD movements
Best Practices
- Always check
git statusbefore committing to see what will be included. - Write clear, concise commit messages describing the "why" not the "what".
- Use
git diffto review changes before staging. - Prefer creating new commits over amending published commits.
- Never force-push to shared branches without explicit permission.
- Stage specific files rather than
git add .to avoid committing unintended files.