I have 2 branches in my git repository:
capsule-os
* remotes/m/ics
capsule-os is branch with my local changes to the remotes/m/ics branch. I work with (and build) the capsule-os branch, but remotes/m/ics updates sometimes, and I want to sync this changes with my local branch (in fact, add my changes to this remote branch). What should I do?
Amber’s answer is correct, but I thought it might be worth adding an answer with the alternative approach of rebasing rather than merging.
If you haven’t published your
capsule-osbranch yet, you may want to “rebase” your changes on to the updatedm/icsbranch, e.g. with:(You might have to resolve some conflicts then – if you can’t easily do that, you can put your
capsule-osbranch back to how it was originally withgit rebase --abort.)As an alternative, you can fetch the new version of the
icsbranch and rebase onto that in one go with:There are lots of different ways of using
git rebase, but they all essentially involve taking a set of commits and, for each of those, trying to reapply the changes the commit introduced onto some other commit. This is frequently used to “move” a set of commits onto an updated upstream branch, to keep the history simple.The reason that I qualified this with “if you haven’t published the
capsule-osbranch” is that rewriting the history of a branch can create difficulties for collaborators who are working on the original version of that branch. However, if it’s still private work, rebasing is a nice way to keep your branch up to date with upstream, and still keeping the history simple.