3

I have a web application that is stable and online. A few weeks ago I decided to begin working a new feature and created a development branch. I have since completed this development and would like to make this feature live.

I have read up on git rebase and while I understand the concept of rebasing a branch I am not sure how this should be applied, in the sense of best practices. I created a second "dummy" local repo to try a few things. My idea is that once a development is complete and stable this should be your new "stable" (master) branch. So I tried:

  • git rebase development master: This worked eventually but was annoying as I expected since it had several conflicts to resolve. However, this meant the master branch has all the new development features.
  • git rebase master development: This was much quicker as there were no conflicts to resolve, however, all the development features remain on the development branch and this is not reflected on my "stable" master branch.

In both cases, once the rebase was complete I had notifications that my local branch had diverged from the remote branch and to git pull to merge the remote branch into my local branch (perhaps another issue).

Since I am new to VCS I am not really sure which is the best practice approach? Can someone offer some advice? I would like to have a main stable branch (master) with my new features. Do most people rebase development onto master and discard (in the sense, it is archived) the "old" master branch? Or should I always rebase master onto development to keep a progression of the "stable" branch and create new dev branches in the future should the need arise?

The other issue is the diverging branches after a rebase. This creates problems on git pull since there are so many diverged commits (see image below).

What are your thoughts? What is the best way to proceed?

Diverging commits after rebasing development onto master

Diverging commits after rebasing master onto development

1 Answer 1

1

git rebase master development: This was much quicker as there were no conflicts to resolve, however, all the development features remain on the development branch and this is not reflected on my "stable" master branch.

Yes: you need to merge (after the rebase) development to master for master to reflect development.

The goal of the rebase (as a first step) is to make sure the rebased development branch does still work on top of the up-to-date master, resolving any possible conflict locally.

Then the merge from dev to master is a trivial one, since all dev commits are already on top of master.

Note that any rebase would require a git push --force to publish the new history of the rebased branch. If you are the only one working on said branch, it is not a big deal.

3
  • Thank you. This is very helpful. In terms of best practices, once you merge rebase dev and then merge dev to master is there a standard period of time to keep the old dev branch? Also with git push --force I presume you meant this for the dev branch in this case? Apr 20, 2022 at 8:27
  • @Zeta-Squared You can simply go on using dev (after being merged to master): new commits will be stored on that "new" (reused) dev branch.
    – VonC
    Apr 20, 2022 at 13:35
  • @Zeta-Squared Also useful, the gitworkflow (one work) option: mentioned in stackoverflow.com/a/71583967/6309 and detailed in stackoverflow.com/a/216228/6309
    – VonC
    Apr 20, 2022 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.