{}const=>[]async()letfn</>var
Development

Git branches: working in parallel without conflicts

A complete guide to working with Git branches for developers. Learn how to create branches, switch between them, merge changes, and resolve conflicts. We analyze the difference between merge and rebase, popular branching strategies (Git Flow, GitHub Flow) and best practices for team development.

К

Kodik

Author

5 min read

What are branches and why do you need them

A branch in Git is an independent development line. Technically, a branch is just a pointer to a specific commit. This makes creating branches an incredibly fast and lightweight process.

The main scenarios for using branches:

  • Development of new functions isolated from the main code

  • Fixing bugs without affecting current development

  • Experimenting with code without the risk of breaking something

  • Parallel work of several developers on different tasks

🔥 100,000+ students already with us

Tired of reading theory?
Time to code!

Kodik — an app where you learn to code through practice. AI mentor, interactive lessons, real projects.

🤖 AI 24/7
🎓 Certificates
💰 Free
🚀 Start learning
Joined today

Basic operations with branches

Create a new thread

You can create a branch with the command:

git branch feature-auth

This command will create a new branch, but will not switch to it. To create a branch and immediately switch to it, use:

git checkout -b feature-auth

Or in a more modern syntax:

git switch -c feature-auth

Switching between branches

To switch to an existing branch, use:

git checkout main

Or:

git switch main

The git switch command appeared in Git 2.23 and was created specifically for switching branches, making the syntax more understandable. git checkout performs many different operations, which is sometimes confusing.

View branch list

To see all local branches:

git branch

The current thread will be marked with an asterisk. To view all branches, including deleted ones:

git branch -a

Useful command for viewing branches with additional information:

git branch -v

It will show the last commit in each branch.

Merge branches

After you have finished working on the function in a separate branch, it must be merged back into the main branch. To do this, use the git merge command.

Fast-forward merge

The simplest case is when there were no new commits in the main branch after creating your feature branch:

git checkout main
git merge feature-auth

In this case, Git will simply move the main branch pointer forward. This is called a fast-forward merge.

Three-way merge

If new commits appear in the main branch after the creation of the feature branch, Git will create a merge commit that combines changes from both branches:

git checkout main
git merge feature-user-profile

Git will automatically create a merge commit with a message like "Merge branch 'feature-user-profile'".

Conflict resolution

Conflicts arise when the same lines in files are changed in different branches. Git cannot automatically decide which changes to leave and asks you for help.

If a conflict occurs, Git will mark the problematic areas in the files:

<<<<<<< HEAD
const apiUrl = 'https://api.example.com/v1';
=======
const apiUrl = 'https://api.newdomain.com/v2';
>>>>>>> feature-api-update

The block between <<<<<<< HEAD and ======= contains changes from the current branch, and the block between ======= and >>>>>>> feature-api-update contains changes from the merged branch.

To resolve the conflict:

  1. Open the file and select the desired changes by deleting the conflict markers

  2. Save the file

  3. Add the file to the staging area: git add filename.js

  4. Complete the merge: git commit

Many IDEs and code editors have built-in tools for visual conflict resolution, which greatly simplifies the process.

Rebase: an alternative to merge

In addition to merge, there is another way to integrate changes — rebase. It moves your branch to the top of another branch, rewriting the history of commits.

git checkout feature-payment
git rebase main

This command will take all commits from feature-payment and apply them on top of the last commit in main.

Differences between merge and rebase

Merge saves the full history and creates an additional merge commit. The history is non-linear, but it reflects the real development process.

Rebase creates a linear history by rewriting commits. This makes the history cleaner and easier to understand, but information about when exactly the branches existed in parallel is lost.

Important rule: Never rebase public branches that other developers are working with. This rewrites history and will create problems for the entire team.

Branch strategies

Git Flow

A popular branching model proposed by Vincent Driessen. Main branches:

  • main — stable production code

  • develop — integration branch for development

  • feature/* — branches for new features

  • release/* — preparation for release

  • hotfix/* — urgent fixes in production

GitHub Flow

A simplified model popular in continuous delivery teams:

  • main — always ready for deployment

  • Feature branches are created from main

  • After review, the changes are merged back into the main branch via a pull request

  • Deployment occurs immediately after the merge

Trunk-Based Development

Minimalist approach:

  • One main branch (trunk/main)

  • Developers commit directly to main or create short-lived branches

  • Feature flags are used to hide unfinished features

  • Requires high discipline and good autotests

Practical advice

Naming branches

Use clear and structured names:

feature/user-authentication
bugfix/login-redirect
hotfix/payment-gateway
refactor/api-endpoints

Regular synchronization with the main branch

If you are working on a feature branch for a long time, regularly pull in changes from main:

git checkout feature-dashboard
git merge main

This will help avoid major conflicts during the final merger.

Removing branches

After merging a branch, it can be deleted:

git branch -d feature-auth

To force the removal of an unmerged branch:

git branch -D experimental-feature

Deleting a remote branch:

git push origin --delete feature-auth

View branch history

Visualization of the history of commits with branches:

git log --oneline --graph --all

This command will show the commit tree with all branches in a compact format.

Working with remote branches

Sending a local branch to the server

git push -u origin feature-api

The -u flag establishes a connection between the local and remote branch.

Getting remote branches

To see new branches from the server:

git fetch origin

Creating a local branch based on a remote one:

git checkout -b feature-api origin/feature-api

Or in short:

git checkout --track origin/feature-api

Conclusion

Git branches are a powerful tool for organizing parallel work on a project. They allow you to isolate the development of new features, safely experiment with code, and work effectively in a team. Understanding the basics of working with branches, merging and resolving conflicts is a necessary skill for any modern developer.

Start simple: create a separate branch for each new task, regularly commit changes and merge the finished functions back into the main branch. With experience, you will find the workflow that best suits you and your team.

Appendix Code offers structured programming courses for beginner developers. The training is based on practical examples and real tasks that will help you quickly start writing code.

Join our Telegram channel, where we regularly publish useful articles, analysis of complex topics and answer questions from novice programmers. Learning together is easier and more effective!

🎯Stop procrastinating

Liked the article?
Time to practice!

In Kodik, you don't just read — you write code immediately. Theory + practice = real skills.

Instant practice
🧠AI explains code
🏆Certificate

No registration • No card