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?
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.
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".
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With