I often have a workflow where I develop some feature in a Git branch, switch to another feature-branch, etc. During development, the original develop branch and the feature branches diverge.
Now when switching branches I am all of the sudden developing on an older version of my project (which is to be expected, of course).
I do wonder however whether something like a "tracking" behaviour can be configured with Git, which would mean that specially-marked feature branches would be automatically rebased on another branch (like develop
or master
). This would simplify a lot, especially rebuilds.
-
recommended reading: Where does my git question go?gnat– gnat2014年10月27日 10:23:41 +00:00Commented Oct 27, 2014 at 10:23
-
Branches can track an upstream for rebase. I don’t know if that existed in 2014, or if that is what you are asking about.Guildenstern– Guildenstern2023年04月28日 20:35:59 +00:00Commented Apr 28, 2023 at 20:35
-
WayBack Machine link: Where-does-my-git-question-go?J_H– J_H2024年02月03日 04:30:43 +00:00Commented Feb 3, 2024 at 4:30
3 Answers 3
No, you just have to
git checkout feature-branch
git merge master|develop
Done, your branch is now up to date. It will also let you a chance to resolve conflicts early. Perform the merge periodically, and you'll be fine.
No, there's no automatic rebasing. The easiest way to achieve a very similar effect is to do single branch development, as recommended for continuous delivery (relevant article).
You can do
git checkout your_branch
git fetch # get the latest
git rebase master
Rebase will replay your changes on top of the latest master. You will need to resolve any conflicts. Conflicts occur when the same line(s) in the same file are edited by both the latest master and the feature branch.
-
fetch
doesn't update master, it updatesorigin/master
(assuming you call the place you fetch from origin). So the last command needs to begit rebase origin/master
bdsl– bdsl2024年02月04日 13:27:03 +00:00Commented Feb 4, 2024 at 13:27