Nick Brown
Nick Brown

Reputation: 1167

Git: Rebase or Merge to update a local branch

Alright, I have a development branch that is tracked remotely and shared by everyone on this project.

Locally I have branched off of this to do some ongoing work. However, in the mean time another developer has committed and pushed changes to the development branch that I would like reflected in my local branch. Is this the time to rebase?

I don't want to simply commit my local branch to development and then start a new branch because I would like to maintain my commit history.

As I understand it, rebase would take the development branch at HEAD and re-apply all of my commits over top of it, but will that overwrite the other developer's changes without throwing a conflict if we have made changes to the same lines?

Upvotes: 3

Views: 1111

Answers (2)

itsbruce
itsbruce

Reputation: 4843

First, you fetch, then you rebase. You don't clobber the other guy's changes by doing this; what you do is redo your changeset so that it's a delta against his changes rather than the earlier version. It eliminates unnecessary and unhelpful merge messages from the logs and makes the log more meaningful if this is really how the development history should be represented.

Go ahead and rebase; sounds like the right thing to do in this case. way too many people just git pull without thinking.

Upvotes: 6

Brian Campbell
Brian Campbell

Reputation: 332846

Yes, you are right that rebase will take the head of the development branch, and re-apply all of your commits on it.

No, it will not overwrite other developers changes without throwing a conflict. If there is a conflicting change, you will need to resolve the conflicts, just like in a merge (fix the conflicts, and use git add to stage the fix), and then tell rebase to continue using git rebase --continue.

Yes, this is an appropriate time to do a rebase. That's how a lot of people work; if they have unpushed local commits, and there are upstream commits, they rebase their local commits before continuing to work or pushing to a public repo.

Upvotes: 5

Related Questions