I am working on a new feature in a new branch, and meanwhile the master has changed.
I would like to update my branch to reflect the changes to master, with the following constraints:
There are lots of answers suggesting that in this situation one should use rebase, but I'm nervous about doing this in case it causes problems for anyone who's already pulled the branch.
Can I just do this?
git checkout mybranch
git merge origin/master
git push origin mybranch
If you've pushed your branch elsewhere you shouldn't rebase it, so a merge is appropriate. Your command sequence at the end is fine.
Your reasoning about the danger of rebase is correct: if someone pulled your branch, he might indeed get into problems, as a rebase rewrites some of the git history. Merge is always safe.
Your sequence is totally correct, and very typical when working with feature branches. Before you ever merge a feature branch into the master, you should merge the master in your feature branch every now and then, so that it does not starts deviating too much from the master. A large deviation could result in many merge conficts when finally merging into the master branch (when the feature is ready). By regularly merging the master branch into your feature branch, you resolve the (possible) conflicts much earlier, the conflicts are smaller and easier to understand.
In your process, line (2) is where you must resolve the conflicts (if any)
You were stating that you want your feature changes only local. But as you pushed/pushes your feature branch, the feature changes are also on the remote server (on a remote branch, not in the master)
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