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 themaster
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 thedevelopment
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?
CodePudding user response:
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.