-
Talinn, Estonia
-
-
support@lnsolutions.ee
Managing Git Feature Branches and Resolving Merge Conflicts
Managing Git Feature Branches and Resolving Merge Conflicts
Read more on Medium
Git is a powerful version control system widely used by developers to manage source code repositories. One of the key features of Git is its support for branching, allowing developers to work on new features or experiments without affecting the main codebase. However, managing branches and resolving merge conflicts effectively are crucial skills for successful collaboration and code management. In this article, we’ll explore common Git branching tasks and how to handle merge conflicts gracefully for feature branches.
Understanding Git Branches
Git branches are independent lines of development within a Git repository. They allow developers to work on different features, bug fixes, or experiments without affecting the main codebase. Here are some essential concepts related to Git branches:
- Creating a Branch: To create a new branch, you can use the
git checkout -b <branch-name>
command. This creates a new branch and switches to it in one step. - Switching Branches: You can switch between branches using the
git checkout <branch-name>
command. This allows you to work on different features or bug fixes seamlessly. - Listing Branches: To view a list of branches in your repository, you can use the
git branch
command. The branch you are currently on will be highlighted. - Deleting a Branch: To delete a local branch in Git, you can use the
git branch -d <branch-name>
command. Be cautious when deleting branches, especially if they contain unmerged changes.
Handling Merge Conflicts
Merge conflicts occur when Git cannot automatically merge changes from different branches due to conflicting changes in the same part of a file. Here’s how to handle merge conflicts effectively:
- Fetching Remote Changes: Before merging branches, it’s essential to fetch the latest changes from the remote repository using
git pull origin <branch-name>
. - Merging Branches: To merge changes from one branch into another, you can use the
git merge <branch-name>
command. Git will attempt to automatically merge the changes. If there are conflicts, Git will pause the merge process. - Resolving Conflicts: To resolve merge conflicts, open the conflicted files in a text editor and manually resolve the conflicting sections. Remove the conflict markers (
<<<<<<<
,=======
,>>>>>>>
) and keep the changes you want to retain. - Committing Changes: After resolving conflicts, stage the changes using
git add .
and commit the merge usinggit commit
. Git will create a merge commit to finalize the merge process.
Working on a feature branch

In this example we start with main and then create a new local branch and switch to it
Read more on Medium