Git&Github 工作流

git clone git@…

克隆项目到本地

git checkout -b my-feature

新建本地分支my-feature

git add .

git commit -m’update’

更新本地分支my-feature

git push origin my-feature

远端新建分支my-feature

  • 此时若远端有了新的 commit,本地 main/my-feature 并不是最新,而my-feature又有了更新

git checkout main

切换到本地主分支main

git pull origin master

更新本地主分支main与远端master一致

git checkout my-feature

切换到本地工作分支my-feature

git rebase main

在本地main最新的基础之上更新我的修改,有可能出现 rebase conflict,手动选择代码解决冲突

git pull -f origin my-feature

将本地my-feature强行推到远端 my-feature

New pull request

远端的my-feature做pull resuest

Squash and merge

远端master做Squash and merge

delete my-feature

远端删除分支my-feature

git checkout main

本地切换到主分支main

git branch -D my-feature

删除本地工作分支my-feature

git pull origin master

更新本地main与远端mater保持一致