-->

Create and merge a git branch to an epic branch

2020-07-26 08:38发布

问题:

I am working on a project, for example, SO/bubbleSort and there I need to create an epic branch called feature/version-1 so from this epic branch there are few developers do the development, so for that, they need to create a separate branch from the epic branch. My question is how can we merge those changes and keep the epic branch with the latest changes.

I have followed the following steps to do so. Is it correct?

The first step checkout to the develop branch

git checkout develop

Create an epic branch under the develop branch

git checkout -b feature/version-1 develop

Create another branch for my development from the epic branch

git checkout -b myVersion feature/version-1

After doing my implementation what do I need to do?

Do I need to give a PR from my branch to the epic branch and merge? OR Is there any way to fulfill my need?

回答1:

so for that, they need to create a separate branch from the epic branch

No, they do not, unless each of their work is so different it needs a long-lasting branch of its own.
If not, they can work on their own local feature/version-1 branch:

git fetch
git checkout feature/version-1

That will track automatically the remote origin/feature/version-1

They just have to do a rebase before pushing their commit, in order to rebase their local work (commits on in their own feature/version-1 branch) on top of what was already pushed by others on that branch (in origin/feature/version-1).

 git fetch
 git checkout feature/version-1
 git rebase origin/feature/version-1

That way, the synchronization is done locally (through the rebase). Any merge conflict is resolved there.
Then the developer does one last test before pushing.


The OP adds:

Here each of their work is so different and the one implementation depends on the other person implementation

Then yes, pushing their own branch and doing a PR to the upstream epic branch is a good way.
But each developer needs to rebase his/her own branch on top of the epic one before force pushing their own branch, in order to synchronize their work with what was accepted in the epic branch.
Then, once pushed, they can do a PR (after the first push), or the PR will be automatically updated (after the next push --force: since each developer is the only one working on their own branch, they can force push it without negative consequences).

git fetch
git checkout myVersion  
git rebase origin/feature/version-1
git push --force