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

Basic operations with branches
Create a new thread
You can create a branch with the command:
git branch feature-authThis 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-authOr in a more modern syntax:
git switch -c feature-authSwitching between branches
To switch to an existing branch, use:
git checkout mainOr:
git switch mainThe 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 branchThe current thread will be marked with an asterisk. To view all branches, including deleted ones:
git branch -aUseful command for viewing branches with additional information:
git branch -vIt 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-authIn 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-profileGit 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-updateThe 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:
Open the file and select the desired changes by deleting the conflict markers
Save the file
Add the file to the staging area:
git add filename.jsComplete 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 mainThis 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 codedevelop— integration branch for developmentfeature/*— branches for new featuresrelease/*— preparation for releasehotfix/*— urgent fixes in production
GitHub Flow
A simplified model popular in continuous delivery teams:
main— always ready for deploymentFeature 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-endpointsRegular 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 mainThis will help avoid major conflicts during the final merger.
Removing branches
After merging a branch, it can be deleted:
git branch -d feature-authTo force the removal of an unmerged branch:
git branch -D experimental-featureDeleting a remote branch:
git push origin --delete feature-authView branch history
Visualization of the history of commits with branches:
git log --oneline --graph --allThis 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-apiThe -u flag establishes a connection between the local and remote branch.
Getting remote branches
To see new branches from the server:
git fetch originCreating a local branch based on a remote one:
git checkout -b feature-api origin/feature-apiOr in short:
git checkout --track origin/feature-apiConclusion
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!
