我正在帮一些人完成一个项目,但我之前从未使用过Git进行协作,因此我的技巧有些生疏,希望能够正确操作。
背景
没有分支。建议直接克隆存储库,然后创建分支。
origin/master
包含当前发布的生产就绪代码。
origin/develop
包含下一个版本的最新开发更改的代码。
我的Git工作流程草稿
Clone the repo to my local machine:
$ git clone <origin-url>
Create new branch:
$ git checkout -b newFeature develop
Makes changes, stage and commit them:
$ git add . $ git commit -m "<message>"
Push changes to remote newFeature branch (this branch does not yet exist in the origin repo):
$ git push origin newFeature
Submit a pull request to merge
origin/newFeature
intoorigin/develop
.Delete the local branch upon acceptance of pull request:
$ git branch -d newFeature
问题
我是否应该确保本地的
develop
分支与origin/develop
保持同步,然后再推送我的newFeature
分支呢?这样做可以帮助我的同事避免合并冲突,并允许快进合并,是吗?如何才能做到最好呢?我应该定期从本地机器上拉取
origin/develop
分支吗?如果我尝试推送分支时代码不是最新的,Git会通知我吗?它会阻止推送吗?
在第2个阶段,是否有必要特别从
develop
分支分支出来?如果我只使用以下命令,会有什么问题吗?$ git checkout -b newFeature
git push -u origin newFeature
命令(尽管这取决于你的push.default
设置和 Git 版本:自 Git 2.0 起默认需要此命令,但在早期版本中不需要)。 - torek