How to merge branches in Git

Merging branches is fundamental for integrating feature work, bug fixes, and collaborative contributions into the main codebase in Git workflows. As the creator of CoreUI, a widely used open-source UI library, I’ve merged thousands of branches from contributors worldwide, managing feature integration and release cycles across multiple repositories. From my expertise, the most standard approach is to use git merge command after switching to the target branch. This method creates merge commits that preserve the history of both branches, enabling clear tracking of feature integration and easy rollback if needed.

Switch to target branch and use git merge to integrate changes from feature branches.

git checkout main
git merge feature/user-authentication

The git merge command integrates changes from one branch into another. First, switch to the target branch (usually main or develop) using git checkout, then merge the feature branch with git merge branch-name. Git automatically creates a merge commit if there are no conflicts, combining the histories of both branches. If conflicts occur, Git will pause the merge and require manual resolution before completing with git commit. The merge preserves the complete development history of the feature branch.

Best Practice Note:

This is the same approach we use in CoreUI development for integrating features and maintaining stable releases. Use git merge --no-ff feature-branch to always create a merge commit even for fast-forward merges, providing clearer project history. Consider git rebase for linear history or squash merging for cleaner commit logs in pull requests.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author