Merging commits
Basic Merge
-
Checkout the Target Branch.
-
Merge the branch containing the commits you want.
git checkout main
git merge feature-branch
The history of both branches remains unchanged, and the merge commit shows that a merge occurred. The divergent paths of the branches are maintained in the commit history.
Squash and Merge
Squashing process combines all the changes from individual commits into one cohesive commit.
git checkout main
git merge --squash feature-branch
git commit -m "Merged feature-branch as a single commit"
Merge Specific Commits
-
Checkout the target branch.
-
Use the commit hashes to cherry-pick specific commits.
git checkout main
git cherry-pick a1b2c3d4 e5f6g7h8
Rebase and Merge
Rebasing can be useful to keep a clean history by applying your commits on top of another branch.
-
Rebase branch containing the commits you want to target branch.
-
Perform basic merge.
git checkout feature-branch
git rebase main
git checkout main
git merge feature-branch