Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I rebase with dev branch before making a pull request?

Our current workflow:

create a feature branch from dev. after developing the feature and having pushed the branch do a the following:

git checkout dev

git pull --rebase (on dev)

git checkout my-feature-branch

git rebase dev

resolve conflicts and then do a git push -f or git push (first time).

My question comes from one of our development team members:

Do we need to do the whole process as is, or can we just make the pull-request directly, especially that the response is always "I am working on a component which is not shared by any other developer" ?

Thanks in advance

like image 309
O.D. Avatar asked Jul 18 '18 14:07

O.D.


People also ask

Should I git rebase before pull request?

Reviewing a Feature With a Pull Request Any changes from other developers need to be incorporated with git merge instead of git rebase . For this reason, it's usually a good idea to clean up your code with an interactive rebase before submitting your pull request.

When should I rebase my branch?

Use rebase whenever you want to add changes of a base branch back to a branched out branch. Typically, you do this in feature branches whenever there's a change in the main branch.

When should you avoid rebasing a branch?

1 Answer. Show activity on this post. Case 1: We should not do Rebase on branch that is public, i.e. if you are not alone working on that branch and branch exists locally as well as remotely rebasing is not a good choice on such branches and it can cause bubble commits.

How do you rebase before PR?

To update by rebasing, click the drop down menu next to the Update Branch button, click Update with rebase, and then click Rebase branch. Previously, Update branch performed a traditional merge that always resulted in a merge commit in your pull request branch.


Video Answer


2 Answers

Let's say, while you are working on your feature-branch, new stuff is integrated onto the dev branch. So the history might look like this:

1 - 2 - 3 - 5 (dev)
    \
     4 - 6 - 7 - 8 (feature-branch)

If you simply create a pull-request and the dev branch maintainer would have to merge it, he would need to deal with potential conflicts -- bad for the dev branch maintainer.

If you rebase the feature-branch branch onto dev and resolve potential conflicts before submitting the pull-request,

1 - 2 - 3 - 5 (dev)
             \
              4 - 6 - 7 - 8 (feature-branch)

it will be just a quick and easy fast-forward merge for the dev branch maintainer.

This workflow enforces developers to resolve conflicts locally and makes the live of the integrator easier.

like image 102
sergej Avatar answered Oct 10 '22 04:10

sergej


Your workflow is just the typical rebase workflow I would expect to see being used to keep a feature branch directly ahead of its ancestor, which in this case is the dev branch. If you want to leave open the possibility of the my-feature-branch fast-forwarding the dev branch during the pull request, then yes, you need to do all these steps. Note that the force push might be required because the rebase on dev can rewrite the history of the feature branch.

As to whether you should be doing a rebase workflow versus a merge or other workflow, this is subjective and depends on many things. But, if rebase does make the most sense, then I agree with your current steps and don't see a way to simplify it.

like image 41
Tim Biegeleisen Avatar answered Oct 10 '22 03:10

Tim Biegeleisen