First, it eliminates the unnecessary merge commits required by git merge. The major benefit of rebasing is that you get a much cleaner project history. But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch. This moves the entire feature branch to begin on the tip of the master branch, effectively incorporating all of the new commits in master. The Rebase OptionĪs an alternative to merging, you can rebase the feature branch onto master branch using the following commands: git checkout feature While it’s possible to mitigate this issue with advanced git log options, it can make it hard for other developers to understand the history of the project. If master is very active, this can pollute your feature branch’s history quite a bit. On the other hand, this also means that the feature branch will have an extraneous merge commit every time you need to incorporate upstream changes. This avoids all of the potential pitfalls of rebasing (discussed below). The existing branches are not changed in any way. Merging is nice because it’s a non-destructive operation. This creates a new “merge commit” in the feature branch that ties together the histories of both branches, giving you a branch structure that looks like this: Or, you can condense this to a one-liner: git merge master feature The easiest option is to merge the master branch into the feature branch using something like the following: git checkout feature To incorporate the new commits into your feature branch, you have two options: merging or rebasing. Now, let’s say that the new commits in master are relevant to the feature that you’re working on. This results in a forked history, which should be familiar to anyone who has used Git as a collaboration tool. Both of these commands are designed to integrate changes from one branch into another branch-they just do it in very different ways.Ĭonsider what happens when you start working on a new feature in a dedicated branch, then another team member updates the master branch with new commits. The first thing to understand about git rebase is that it solves the same problem as git merge. In this article, we’ll compare git rebase with the related git merge command and identify all of the potential opportunities to incorporate rebasing into the typical Git workflow. The git rebase command has a reputation for being magical Git voodoo that beginners should stay away from, but it can actually make life much easier for a development team when used with care.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |