3 ms·
> 4. To keep your feature branch fresh and up to date with the latest changes in master, use rebase Could somebody please explain this more? My understanding o
by crazygringo 13y ago
> 4. To keep your feature branch fresh and up to date with the latest changes in master, use rebase
Could somebody please explain this more? My understanding of rebase which comes from [1] is that it's used to bring a feature branch onto a master branch, or similar, and 'erase evidence' of there ever having been a branch, and squash the intermediate commits on that branch, to make things cleaner.
For bringing changes on the master branch into your feature branch, what's the benefit of using rebase instead of just normally merging the changes in? I'm clearly missing something here. They say 'Resolving conflicts during the rebase allows you to have always clean merges at the end of the feature development.', but I don't see what merge vs rebase has to do with resolving conflicts -- you have to resolve conflicts when you merge master into your feature branch just the same.
I can understand using rebasing to keep the master branch's history 'clean', but what's the reason with a feature branch?
[1] http://git-scm.com/book/en/Git-Branching-Rebasing http://git-scm.com/book/en/Git-Branching-Rebasing
- prezjordan 13y agoRebasing will first undo your changes, get the latest changes from the target branch, then slap all of your changes at the HEAD. It makes things a lot cleaner and easier to revert (without digging through the reflog), whereas merging will intertwine your changes with the master branch. I use it to keep things organized, and also (as you mentioned) for squashing consecutive commits.
- hdevalence 13y agoIn this case, we want to have a logical history that says: this branch has these features A, B, C, D, and rebasing means that we can have the feature branch just have these commits, instead of "A, and then merge in some changes someone else happened to do, then B, C, then some other merges, then D."
- deleted 13y ago[deleted]
- ricardobeat 13y agoTLDR: avoid millions of Merge branch master into xxx commits on a busy project, keeping commit history clean, and allow reverting merged branches easily.
- crazygringo 13y agoOK. Re-reading the article for like the fifth time, I finally realize where I'd gone wrong -- the fact that rebasing from branch to master, and rebasing from master to branch, are pretty different things, used in different ways. In case this helps anybody else: I had always understood rebase as a mechanism that replaces merging a feature branch onto master, that allows you to squash all the 'messy' development commits on the feature branch, onto a single nice clean commit on master. In this model, you can be as messy as you want on the feature branch (with 'whoops bugfix' commmits and lots of merging in), and the feature branch is generally short-lived -- once you rebase+squash it onto master, the feature branch gets deleted, and you start a new one if necessary for further work. The proposed model is the opposite -- you try to keep a clean feature branch. Every time you want to fold in changes from master, you do it as rebase, which has nothing to do with squashing anything -- it's about bringing forward the starting point of your feature branch to match master's current state. Then, when it's time to bring feature into master, you merge, not rebase, so the branch history is preserved, it's just nice and clean. And I suppose you can keep the feature branch around for more work on it, so it's almost more of a long-lived 'topic' branch with a bunch of individual features stringing along it. The funny thing is, I've never seen a blog post that talks about both kinds of rebasing at once. Every one I've seen seems to look at it from one viewpoint or the other, which it possibly why rebasing can get so confusing (maybe I've missed one that does explain it well, both ways). The "git-scm" site describes the first way, but this blog post helped me understand this other way of rebasing: http://blog.marcomonteiro.net/post/are-you-a-merge-or-rebase-guy http://blog.marcomonteiro.net/post/are-you-a-merge-or-rebase... Thanks!
- encoderer 13y agoI hope this doesn't confuse you, but I do feel compelled to add.. In both examples you mentioned, you merge onto master. You would break your teammates repos if you rebased a topic/feature branch onto master. You ARE right, that before such a merge, it's a common practice to squash your commits on the feature branch to clean it up and then merge a single commit over to master. (To squash you use git rebase -i but you're squashing not rebasing). If you were to actually rebase this branch into Master instead of merging it, it would change the commit hashes for commits already in master, leading to awful merge conflicts the next time a teammate tried to pull down your changes. I wanted to mention this to hopefully connect the last few dots. The reason most articles don't talk about "both" these ways, is because really there is only one way, with a few different choices. Maintaining a branch: If you need to bring changes from Master into a long-running branch, you can either do so with merge or rebase. Rebase is cleaner IMO. Preparing to integrate your work into master: You can either squash some or all of your commits, or you can keep the history as-is. Integrating into master: You always do this with a merge.