my-git

Everyday Git Commands

English 中文

This is not a complete command manual; it only preserves the most commonly used path for daily development.

The goal is to enable you to reliably complete:

Pull latest code -> Create branch -> Modify -> Check diff -> Commit -> Push -> Open PR

Starting a Task

git switch main
git pull --rebase
git switch -c feat/my-task

If your team’s main branch is named master or develop, replace it according to the actual branch used by your team.

Checking Current Status

git status
git diff
git diff --stat

Always check the diff before committing.

Especially during AI-assisted development, first confirm there are no unrelated files, formatting noise, temporary logs, secrets, or build artifacts.

Staging and Committing

Use git add -p to stage in chunks:

git add -p
git commit -m "feat(scope): describe change"

If the changes this time are very small, you can also directly:

git add <file>
git commit -m "fix(scope): describe bug fix"

Syncing with the Main Branch

git fetch origin
git rebase origin/main

If you are unsure whether you should rebase, read Rebase vs Merge first.

Pushing the Branch

git push -u origin feat/my-task

Then create a PR on GitHub / GitLab.

Temporarily Switching Tasks

git stash push -u -m "wip: current task"
git switch main
git switch -c hotfix/urgent-fix

To restore:

git switch feat/my-task
git stash apply

When Something Goes Wrong

Capture the current state first:

git status
git log --oneline --decorate -10
git reflog -10

Then follow the Git Troubleshooting Playbook to select a recovery method.

Further Reading