简体   繁体   English

我的git工作流程是否正确且符合我的团队?

[英]Is my git workflow correct and in accordance with my team?

I'm helping some guys out with a project and I haven't before used Git collaboratively, so I'm rusty and want to get this right. 我正在帮助一些人参与一个项目,我之前没有合作过使用过Git,所以我很生气,想要做到这一点。

Background 背景

There is no forking. 没有分叉。 I have been advised to make a direct clone of the repo, and then branch. 我被建议直接克隆回购,然后分支。

origin/master contains the production-ready code for the current release origin/master包含当前版本的生产就绪代码

origin/develop contains the code for the latest development changes for the next release origin/develop包含下一版本的最新开发更改的代码

My Git workflow draft 我的Git工作流程草案

  1. Clone the repo to my local machine: 将repo克隆到我的本地计算机:

    $ git clone <origin-url>

  2. Create new branch: 创建新分支:

    $ git checkout -b newFeature develop

  3. Makes changes, stage and commit them: 进行更改,分阶段并提交它们:

     $ git add . $ git commit -m "<message>" 
  4. Push changes to remote newFeature branch (this branch does not yet exist in the origin repo): 将更改推送到远程newFeature分支(此分支在原始仓库中尚不存在):

     $ git push origin newFeature 
  5. Submit a pull request to merge origin/newFeature into origin/develop . 提交拉取请求以将origin/newFeature合并到origin/develop

  6. Delete the local branch upon acceptance of pull request: 接受拉取请求后删除本地分支:

    $ git branch -d newFeature

Questions 问题

  • Am I right in thinking that I need to ensure my local develop branch is up to date with origin/develop before I push up my newFeature branch? 在我推动newFeature分支之前,我是否正确地认为我需要确保我的本地develop分支是最新的origin/develop This way, I will help my colleague to avoid merge conflicts and allow for a fast-forward merge? 这样,我会帮助我的同事避免合并冲突并允许快速合并?

  • What is the best way to do this? 做这个的最好方式是什么? Should I pull the origin/develop branch to my local machine at regular intervals? 我应该定期将origin/develop分支拉到我的本地机器吗?

  • Will Git notify me that the code is not up to date when I try to push the branch? 当我试图推动分支时,Git会通知我代码不是最新的吗? Will it block the push? 它会阻止推动吗?

  • Is it necessary to branch off develop specifically, at stage 2? 是否有必要在第2阶段专门develop Does it matter if I just use this command? 如果我只使用这个命令有关系吗?

    $ git checkout -b newFeature

Am I right in thinking that I need to ensure my local develop branch is up to date with origin/develop before I push up my newFeature branch? 在我推动newFeature分支之前,我是否正确地认为我需要确保我的本地开发分支是最新的origin / develop? This way, I will help my colleague to avoid merge conflicts and allow for a fast-forward merge? 这样,我会帮助我的同事避免合并冲突并允许快速合并?

Yes. 是。 Before you do your push: 在你做推之前:

git checkout develop
git pull origin develop
git checkout newFeature
git rebase develop

This assumes that nobody else as worked on newFeature , as in your scenario. 这假定没有其他newFeature在你的场景中一样工作在newFeature If someone else got your branch too, then the rebase might need additional communication with them, or you would maybe (although I hate that, personally, as it is completely wrong on all levels, though most people do it this way), merge develop into newFeature instead. 如果其他人也得到你的分支,那么rebase可能需要与他们进行额外的沟通,或者你可能会(尽管我个人认为,因为它在所有级别上完全错误,尽管大多数人这样做),合并develop而改为newFeature

What is the best way to do this? 做这个的最好方式是什么? Should I pull the origin/develop branch to my local machine at regular intervals? 我应该定期将origin / develop分支拉到我的本地机器吗?

Absolutely. 绝对。 With git, you try to do as frequent committing, pulling, pushing as you can. 使用git,你可以尽可能频繁地提交,拉动,推动。 The earlier you do it, the less likely it is that you get a monster merge which leaves you with no way out (in the sense that you can't understand what the huge change did). 你做得越早,你获得怪物合并的可能性就越小,这让你没有出路(在某种意义上你无法理解巨大的变化是什么)。 Smaller units are much easier to handle. 较小的单位更容易处理。

Will Git notify me that the code is not up to date when I try to push the branch? 当我试图推动分支时,Git会通知我代码不是最新的吗? Will it block the push? 它会阻止推动吗?

Yes, it will not allow that and give you a meaningful message. 是的,它不会允许这样,并给你一个有意义的消息。 You can only push either a fast-forward, or, if a fast-forward is not possible (ie, you diverged), you can do a forced push, which is like replacing the target, and will get you into trouble with your colleagues unless you are the "master of all". 你只能推快进,或者,如果快进不可能(即你分道扬),你可以进行强制推动,就像更换目标一样,会让你的同事遇到麻烦除非你是“所有人的主人”。 You can never do an implicit merge while pushing, it's "either/or", by design. 在推送时你永远不能进行隐式合并,它是“或者/或”,设计。

Note that the exception here is "your" newFeature branch, assuming you are the only one working on it. 请注意,此处的例外是“your” newFeature分支,假设您是唯一正在处理它的人。 Then, after your rebase as shown above, you will have exactly this "blocked" situation and you must use "--force" with the push to get it to the remote. 然后,在如上所示的rebase之后,您将完全处于“阻塞”状态,并且您必须使用“--force”来推送它到远程。 As long as nobody else pulled your branch and worked on it, this is fine though. 只要没有其他人拉你的分支并继续工作,这很好。

Is it necessary to branch off develop specifically, at stage 2? 是否有必要在第2阶段专门开展发展? Does it matter if I just use this command? 如果我只使用这个命令有关系吗? git checkout -b newFeature

This command branches off of whatever is the current branch in your working directory, so in theory it could go wrong if you get confused. 这个命令分支出工作目录中当前分支的任何内容,因此理论上如果你感到困惑就会出错。 After the clone, by default, the master branch is active. 克隆后,默认情况下, master分支处于活动状态。 So yes, you will either need to specifiy develop explicitely, or do a git checkout develop beforehand. 所以,是的,您需要明确指定develop ,或者事先进行git checkout develop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM