高频工作流 Pro Git · 第 5 章

bash · 新项目推送 GitHub
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin <URL>
git push -u origin main
bash · 日常开发循环
git switch main && git pull --rebase
git switch -c feat/xxx
# 修改代码 …
git status && git add .
git commit -m "feat: xxx"
git push -u origin feat/xxx
bash · 同步上游 fork
git remote add upstream <原仓库URL>   # 只需配置一次
git fetch upstream
git switch main
git rebase upstream/main
git push
bash · 交互式变基整理本地提交
git rebase -i origin/main
# 在编辑器里:pick 改 s(squash) 合并、reword 改说明、drop 丢弃
git push --force-with-lease
bash · 紧急修复 hotfix
git switch -c hotfix/bug main
# 修复并提交 …
git switch main && git merge --no-ff hotfix/bug
git tag -a v1.0.1 -m "修复登录崩溃"
git push origin main --tags