How to Merge Local Branches in Git
-
the
git merge
Command - Use Fast Forward Merge to Fix Minor Features and Bugs in Git
- Use 3-Way Merge When Working on a Large Feature in Git
This article will introduce the git merge
command and how you can use it to merge local branches in Git. We will look at how the command works and the merging process.
the git merge
Command
Definition: We use the git merge
command to integrate different branches into a single branch. This makes it easy for developers to work on distinct features in a project.
How the command works: You can merge two or more branches using the git merge
command.
The merge process: Follow these simple steps to start the merging process.
-
Run the
git status
command. This will point theHEAD
to the recipient branch.Switch to the recipient branch using the
git checkout <recipient branch>
command.
- Update your master branch with the latest remote commits using the
git fetch
andgit pull
commands. - Merge the branches by running the
git merge <your branch name here>
command.
Use Fast Forward Merge to Fix Minor Features and Bugs in Git
We use the fast-forward merge to fix minor features and bugs. This type of merger will combine the history of your branches linearly.
Here is an illustration.
Use 3-Way Merge When Working on a Large Feature in Git
This is an alternative to the fast-forward merge. We use this when several developers are working on a large feature independently.
Git invokes a 3-way merge when the histories of your branches diverge. Here is an illustration.
If a conflict occurs, run the git add <conflicted file>
command and commit to finishing up the process.
The git merge --no--ff
command creates a merge commit in fast forward, and 3 way merge.
The git merge --squash
command combines individual commits to one. This helps keep your project clean.
The git merge --abort
command ends the merging process when a conflict occurs and restores your project.
John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.
LinkedIn