Reputation: 21481
I'm a bit mixed up with all the merge/rebase war in git.
Let's say I checkout a new branch for my feature. I commit a few times. But then someone pushes some change to master, and I want that change for my current work. I'd like to have all the new changes pulled to my branch, and have my commits to be replayed on top of those new changes.
What should I do to have my local changes replayed on top of those, without rewriting the history of what is already on the server?
Upvotes: 3
Views: 2244
Reputation: 131
As Schleis stated, as long as you haven't pushed your feature branch out to the remote repository you would want to do a git rebase master
.
Here are the steps I would use:
git checkout master
git pull
git checkout featureBranch
git rebase master
This will switch you to the master branch, then pull all the latest commits for master. Then switch back to your feature branch and replay the feature commits them on top of master.
Upvotes: 1
Reputation: 43700
It all depends on if your new branch has been pushed to the remote also or not.
If it isn't, you can just do git rebase master
on your branch. This set aside all your commits on the branch, apply the new commits from master and then try to apply your commits one by one. If your commit causes a conflict, git will make you fix the commit so that the changes make sense. (This would happen if you changed a line that was already changed in a previous commit and git is not sure what you exactly intend to happen).
If your branch is on the remote, doing a git rebase
is not a good idea. You will be changing the history of your branch and anyone that has pulled the branch will have difficulties with getting the new commits. In this situation, it is better to just do a git merge master
so that you avoid changing history on the remote.
http://www.git-scm.com/book/en/Git-Branching-Rebasing#The-Perils-of-Rebasing
Upvotes: 3