Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git pull --rebase origin master appears to rebase from the beginning every time

We frequently branch out from master to work on large feature branches. These feature branches are usually worked on for days or even weeks before being merged with master (as much as best practice dictates that we need to merge as frequently as possible, practically it could be different).

As such, we try as much as possible to git pull --rebase origin master in order to remain updated with master. However, we'd occasionally encounter the situation where e.g.:

1) Branch out from master branch to feature/new-branch

2) Make changes in feature/new-branch and commit changes.

3) git pull --rebase origin master to put commits on top on master. Fix any conflicts and git add . + git rebase --continue

4) Make more changes in feature/new-branch and commit changes.

5) git pull --rebase origin master again.

However, at step 5), the process requires us to fix the same conflicts from step 3). Which can be tedious.

Is this the right best practice git flow and if not, what else can we do to make the process more efficient?

like image 587
Wei Jia Chen Avatar asked May 16 '16 03:05

Wei Jia Chen


People also ask

What does git pull rebase origin master do?

Git pull rebase is a method of combining your local unpublished changes with the latest published changes on your remote. Let's say you have a local copy of your project's main branch with unpublished changes, and that branch is one commit behind the origin/main branch.

How do I stop a rebasing branch?

If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort".


2 Answers

If you find yourself fixing the same conflict, try and activate git rerere ("reuse recorded resolution").

git config --global rerere.enabled true

That will record for you those conflict resolution.

See more at "Fix conflicts only once with git rerere" from Christophe Porteneuve

if you prefer rerere to auto-stage files it solved (I do), you can ask it to: you just need to tweak your configuration like so:

git config --global rerere.autoupdate true
like image 165
VonC Avatar answered Sep 23 '22 05:09

VonC


You can also git merge the master branch into your feature branch to keep getting the latest changes and ease the transition to master.

For a long running branch (which you shouldn't do, but hey, reality isn't perfect :D) I usually prefer this option to avoid rewriting the entire branch history, which the --rebase does.

like image 33
Hugo Ferreira Avatar answered Sep 26 '22 05:09

Hugo Ferreira