简体   繁体   中英

Will GitHub allow a merge or rebase of a “branch of another branch”?

I have a unique scenario where I'm working with one other person on a project (that comprises a single GitHub repo) and I'm responsible for the design, some development & doing the code reviews + PR merges. I want to try and stick with GitFlow as much as possible here, and I only want to be the one who can merge PRs from feature branches back into develop. So the auth model I'm going with (at least tentatively) is:

  • I have read/write access to master and develop
  • The other dev only has read access to develop

So now we're in an interesting flow here:

  1. The other dev cut a feature branch (say feature/12345 ) off of develop and worked on it for a few days then pushed his changes to GitHub
  2. It was going to take me several days to get around to code reviewing his work and I didn't want him to be held up, so I had him cut the next feature branch (say feature/23456 ) off of his first feature branch and begin working.
  3. Over the next several days I got around to code reviewing feature/12345 , made some changes to it and then pushed those changes. At the same time he worked on feature/23456 .
  4. Satisfied with feature/12345 , I merged it into develop and asked him to pull my changes into his feature/23456 .

Will he be able to create a PR to merge feature/23456 into develop , or will this "branch of a branch" scenario screw things up with GitHub? Will I be able to actually do the merge, or do I need to do some kind of rebase (if so what do the commands for this look like)?

If your colleague hasn't yet pushed feature/23456 to GitHub, he should pull updated develop and rebase feature branch on top of it:

  • check out feature/23456
  • perform git rebase develop

That's it, now his feature branch looks like it was always growing from the top of the develop .

If rebasing isn't an option, most probably, git will be able to handle merging branch of another branch just fine without additional magic, but can't say for sure.

If for some reason things go bad way, there is always dumb and not elegant, but bullet-proof solution. It's always possible to create new branch from develop and simply cherry-pick all necessary commits from feature/23456 into it, making "fresh duplicate" of it to keep things simple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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