Background/Situation
A user has created a feature branch (e.g., DEF) based indirectly on their master branch (e.g., master -> ABC -> DEF). No new commits have been added to the master branch since the feature branch diverged. The goal is to update the master branch to include all the changes from the DEF branch.
Question
How can to update master branch to point to the latest commit of my feature branch DEF?
Answer
Since no new commits were added to the master branch after the DEF branch was created (even indirectly), it is possible to perform a fast-forward merge. This type of merge simply moves the master branch pointer forward to the commit pointed to by DEF, resulting in a linear history without creating an extra merge commit.
To merge the DEF branch into master using the IDE:
- Ensure the
masterbranch is checked out. Switch to it using the Git Branches popup (usually in the bottom-right status bar) or via the Git tool window (View | Tool Windows | Git). Selectmasterand choose Checkout. - Open the Git tool window (
View | Tool Windows | Git) and go to the Log tab. - Locate the
DEFbranch in the branches pane or the log view. - Right-click on the
DEFbranch. - Select the option Merge 'DEF' into 'master'.
The master branch will now point to the same commit as the DEF branch.
Note: If there had been commits on master since DEF diverged, a standard merge would create a merge commit. To maintain a linear history in that scenario, it is needed to rebase DEF branch onto master before doing the mentioned fast-forward merge operation:
- Checkout
DEF - Right-click on
masterbranch > Rebase 'DEF' onto 'master'
After rebasing, continue with the steps outlined above for merging DEF into master.
Warning: Keep in mind that doing rebase, rewrites the branch history (changes commit hashes). Therefore, it is not advised to use it, when working on a repository in a team – as it can lead to corrupt/broken repository history. On the other side, git merge doesn't rewrite history.
Comments
0 comments
Please sign in to leave a comment.