$ git merge feature Output Updating 1c80cb1. So, if two branches have not diverged and there is a direct linear path from the target branch to the source branch, Git runs a fast forward merge. The concept of fast forward merge in git is very similar to this solution. EXAMPLE Remove-DeletedGitBranches Removes merged. Preparing to Merge a Branch in Git We’ve got a small development project with a local Git repository and a remote Git repository. I have two local branches called master and test and two remote branches origin/master and origin/test. Like most actions in Git, you perform merges in your local repository and push them to your remote repository. From this point forward, we can say this is our new MAIN directory. If you want to merge your master branch into another branch, you can even do that too. Solution 02 − Since there is no additional change in the MAIN directory and everything in MAIN is essentially the first version of BUGFix directory, we can simply rename BUGFix to MAIN. Most often there are only two branches involved, but in fact, there can be any number if there are more than two, it is called an octopus merge. This is not the best solution as copy operations may take long time if we have many files in the Bugfix version 2.0 folder. Solution 01 − Copy all files from Bugfix to Main. Once we have completed the changes in bugfix, how do we bring the changes back to the MAIN folder? Now let’s say we made changes in the BugFix directory and made it to BUGFix_V2.0. Code in BUGFix_V1.0 is identical to the code in the MAIN directory. We take a copy of this directory and call it as BUGFix_V1.0. The code in this directory is of version 1.0. Let us say we have a directory called MAIN_V1.0. Let us understand fast-forward merge through a real-world example. In order to merge the changes to the master branch, all git has to do is to change the pointer of master forward. You can also install other mergetools if you like. Typing ' git config merge.tool vimdiff ' will configure vimdiff as the mergetool of choice. You can choose to configure your mergetool. There is a linear path from feature to master. To activate these tools, simply type git mergetool the moment after you've triggered a local merge conflict. Push the hotfix branch: git push origin hotfix. Now we need to bring the changes to the master branch. Cherry-pick the commit to your hotfix branch: git checkout hotfix git cherry-pick abc123. Now let us switch to the feature branch and do a couple of commits. Merging is straightforward checkout master, and merge the detached branch: git checkout master git merge detached-branch This works well if you’re integrating into a branch that needs approval, as is the case with pull requests and code reviews. At this point both feature and master are pointing to the same commit. In git a branch is nothing but a pointer to a commit. Next, we create a branch called feature branch. Let us look at an example implementing fast-forward merge. In fast-forward merge, git simply moves the source branch pointer to the target branch pointer without creating an extra merge commit. Fast forward merge can be performed when there is a direct linear path from the source branch to the target branch.
0 Comments
Leave a Reply. |