git checkout login-pageĬheckout the login-page branch after pulling the latest from the master branch 7. Make sure to be in the feature branch that you want to rebase. These are the steps to rebase a branch in Git. *Notice in the git tree structure we have a login-page branch and a master branch. Example of a repository with a login-page branch For the sake of making it simpler to follow, we are going to have as a reference the following diagram. Now that you understand what the rebase does in Git, we will show you the steps to follow when starting a rebase. However, to start a rebase the only thing you should know is the name of the branch you are rebasing onto. The rebase commands have different configurations that can be used prior to starting rebasing. In other words, you would get all of the latest changes from master branch in feature A branch as if those commits happened first prior to you making commits to feature A branch, making sure feature A branch is up to date with master branch. If you use the rebase command onto master branch, you will update feature A branch base commit. Hence, in case you decide to merge feature A branch to master, there is a possibility of running into conflicts. However, since there are new changes in master branch after merging feature B branch, feature A branch no longer has the latest changes from master branch. Meanwhile, you have been working in feature A branch. Hence, it is normal for that person to merge the feature B branch to the master branch to update the main codebase typically used for production deployments. In this scenario, we are going to assume someone in the team has finished their development in feature B branch. Let’s say, you created feature branch A, and someone else created feature branch B. Whenever we create a feature branch, the feature branch is created off of a specific branch, typically the latest commit of the master branch.Īs there are more people working on a project, other feature branches are created. One more thing: There are lots of reasons to use git rebase -onto - some of which A gnieszka Małaszkiewicz calls out in her excellent post, e.g., quickly removing commits from the current branch.During software development, it is typical to have a master or a main branch and multiple feature branches. ( Update: to avoid this problem, check out Git Rebase On Rebased Branches and Other Fun, Redux where I revist the problem and solve for this annoyance.) My one gripe with these approaches is that they result in a new branch, severing the tie to the remote server. Our current tip for Feat-B, however, diverges earlier and the hashes for Feat-A in its chain are now outdated.Īnd with that, we can push the new branch up to remote and carry on our merry way! ConclusionĪt the end of the day, we were able to successfully resolve the history for our branch and have our feature branch accurately reflect the history we were seeking. Our current tip for Feat-A is 394f56b5 and includes intermediate commits merged into develop.It shows that from c59a0f29, we have two divergent paths: It’s worth noting that while this post will explore resolving this particular issue, the solutions I found are broadly applicable - whether you need to move commits around in history, quickly remove commits from history, etc.įor the purposes of discussion, I’ll use the following example git log. Rebase Feature B off of the new Feature A.Cut a new branch off of Feature A and cherry pick the commits.There are various solutions available to fix this problem. The issue isn’t so much that I cut another branch (Feature B) off a feature branch (Feature A) - it’s that the Feature A eventually needed to be modified and we rebase - meaning that the chain of commits I was expecting to take me back to develop on Feature B are now deprecated and if I don’t fix it, will likely result in duplicative commits at best but more likely undoing the changes that led to the rebase in the first place. Recently, I ran into a bit of a pickle recently when I decided to plow ahead with new feature work before the work I’d just finished had been incorporated into the main branch. Update I wrote a follow up to this walking through similar examples in Git Rebase On Rebased Branches and Other Fun, Redux.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |