Key concepts

Merging

In Git, merging is the process of combining changes from one branch into another. This is typically done when a feature or bug fix is completed on a separate branch and needs to be integrated into the main branch of the project. Merging allows you to bring together the changes made in different branches, creating a unified version of the project that incorporates all the updates.

Merging is an essential operation in Git because it enables collaborative development and parallel work on different features or bug fixes. By working on separate branches, developers can work independently without interfering with each other's progress. Once the work on a branch is complete and tested, it can be merged back into the main branch, making the changes available to everyone.

When performing a merge, Git automatically attempts to combine the changes from the source branch into the target branch. If the changes do not conflict with each other (i.e., they modify different parts of the code), Git will perform a "fast-forward" merge, simply moving the target branch pointer to the latest commit of the source branch.

However, if there are conflicting changes (i.e., both branches have modified the same lines of code), Git will prompt the user to manually resolve the conflicts before completing the merge. This involves reviewing the conflicting changes, deciding which changes to keep, and modifying the code accordingly.

Examples

Suppose you are working on a web application and need to implement a new user registration feature. You create a new branch called login-form-feature to work on this feature:

Run in Terminal:
git switch -c login-form-feature

After completing the feature and testing it thoroughly, you want to merge the changes back into the main branch:

Run in Terminal:
git switch main
git merge login-form-feature

Git will attempt to merge the changes from the login-form-feature branch into the main branch. If there are no conflicts, the merge will be completed automatically.

© 2024-2025 GitByBit.All rights reserved.

Hi! I'm Alex, creator of GitByBit.

And this is Gitopedia—a reference that summarizes knowledge in my Git course.

Gitopedia is designed to be a personal knowledge base. When you progress through the main Git course in VS Code, you unlock all of these topics, one by one, bit by bit. This gives you time to digest the information and gradually build the mental model of Git. Here's an example of how it works:

Learning directly in VS Code lets you practice Git exactly as you would in real life, doing real jobs, writing real code. In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.

The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.

Learn Git in VS Code