0

I have a question about the git merge workflow.

I have worked on a ticket and finished it, added a merge request into the main branch and now comes in my next ticket I should work on.

Is it a good practice to branch off the main branch or the last ticket's branch for working on the second ticket, while I am still waiting for review and merge approval of the first ticket?

Branching off the main will leave out all the changes in the ticket-1-branch, while branching off ticket-1-branch still needs approval.

Is there any rough guideline as how to proceed in such situation?

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
Student
  • 708
  • 4
  • 11

3 Answers3

2

If the next ticket is not dependent on the one that you've worked earlier (those changes are not needed for the next ticket) then the best approach would be just creating another branch from the main.

But if the ticket is dependent, then you can create another branch from your current branch (of the previous ticket) and continue working on that.
And as soon as the previous branch is merged just rebase your new branch with main (or cherry pick the new commit if needed).

P.S. Here's the branching strategy that we use in general.

Just Shadow
  • 10,860
  • 6
  • 57
  • 75
  • 1
    This is my preferred approach. I try to avoid branching off of pending requests, but when I do, I will rebase onto `main` as soon as the first request is complete. If the first branch was rebased, you may not be able to do a straight rebase to `main`. Instead you need `git rebase --onto main ` or just substitute that branch name with the last commit ID from the previous branch. – TTT Nov 02 '21 at 15:28
1

My consolidated approach is to solve the second issue starting from the master branch.

In the meanwhile, if the first task was approved, I merge it into the second branch, and I validate it again.

The reason is that you cannot work on a code which may be wrong.

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
1

To add to given answer, I would not touch branch that is under code review.

Then it may be merged with some not working code or pull requests may be harder to review.

So I would create new branch off from the main master branch and work on new things there.

Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69