Home > Net >  Github create a branch from a development branch but what if I have to create multiple branches
Github create a branch from a development branch but what if I have to create multiple branches

Time:06-19

I am confused I'm kinda new to GIT. I'm assigned multiple issues I have to work on and I'm asked to create a new branch for each issue.

For example:

  • Issue #1 LPD-xxx_change_something_1
  • Issue #2 LPD-xxx_change_something_2
  • Issue #3 LPD-xxx_change_something_3

Now, I'm confused about what If I create a branch LPD-xxx_change_something_1 (issue #1) from the development branch and finished the task, and create the PR (not merged yet).

And, then I want to start working on issue #2 should I create a clone branch from the development branch or Issue #1 branch?

CodePudding user response:

And, then I want to start working on issue #2 should I create a clone branch from the development branch or Issue #1 branch?

development, unless you cannot start issue2 without the code of issue1.
In which case, start from the issue1 branch.

The truth is: it does not matter from where you start.
It matters where you end up with your PR branches.

You will have to rebase them on top of an updated origin/development before each PR can be fast-forward merged by the project maintainer.

Once issue1 is merged:

git switch issue2
git fetch
git rebase origin/development
git push --force

CodePudding user response:

Trying to give you a quick answer: Ideally, it should be from the development branch.

Reason: Imagine an issue is found for your PR for issue #1, and you need to fix it before merging. If you open a Branch for issue #2 from the issue #1 branch, both of your issues will be blocked until you solve whatever problem was found on Issue #1.

But if you open the branch for issue #2 from the development branch, this means your issue #2 branch is completely independent of issue #1. So you can create another PR for issue #2 while you work on the fix for the problem found in Issue #1.

That was the simple answer.

Now giving you a more elaborated answer, you said you were assigned those issues. From that, I understand you are part of a project, that has a team and it's not just you.

Considering it is probably in a work scenario, I believe the best thing for you to do is to check what is the Branch and SCM policy. Any well-maintained project should have a document with those clearly defined.

If there is no such document, I would check with the other members of the project how they handle this situation, they probably have a pattern that is being followed and just not documented.

In my career in software development, in most of the projects I worked on, my simple answer would apply. But branch rules can be quite different in some projects, and I recommend you check what is the project rules for SCM, to make sure you are following them.

  • Related