Git Branch Types and Local vs Remote Branches
1. What are main, feature, release, and hotfix branches?
These are common branch naming and workflow conventions used by development teams to organize different types of work.
Git itself does not require feature, release, or hotfix branches. They are part of a team's branching strategy.
Main Branch
The main branch is typically the primary branch of a repository and usually represents stable or production-ready code.
Common name:
main
Older repositories may use:
master
Example:
main
|
A ---- B ---- C
In many teams, developers avoid making feature changes directly in main. Instead, they work in separate branches and merge changes after review/testing.
Key Points
- Usually the primary branch.
- Often contains stable or production-ready code.
- Commonly protected using branch policies.
- Changes may enter through Pull Requests (PRs).
Feature Branch
A feature branch is created to develop a new feature independently.
Example:
feature/login
feature/payment
feature/user-profile
Suppose you need to implement login:
git switch main
git switch -c feature/login
Development happens separately:
main
A ---- B
\
C ---- D
feature/login
After development and testing, the feature can be merged back:
git switch main
git merge feature/login
Key Points
- Used for new functionality.
- Usually created from the team's integration or main branch, depending on workflow.
- Keeps incomplete work isolated.
- Usually deleted after successful merge.
Release Branch
A release branch is used when preparing a specific version of an application for release.
Example:
release/2.0
A team might create it when feature development for version 2.0 is complete:
git switch -c release/2.0
The release branch can be used for final activities such as:
Bug fixes
Testing fixes
Version changes
Release configuration
Documentation updates
Conceptually:
develop
|
+---- release/2.0
|
Final testing
Bug fixes
|
v
main
This pattern is especially associated with workflows such as Gitflow. Some teams using trunk-based development do not use release branches.
Key Points
- Used to prepare a release.
- Allows final stabilization without blocking other development.
- Normally should not receive unrelated new features.
- Often merged into the production branch when the release is ready.
Hotfix Branch
A hotfix branch is used to fix an urgent problem in production.
For example:
hotfix/payment-error
Suppose production contains a critical payment issue.
Create the hotfix from the production branch:
git switch main
git switch -c hotfix/payment-error
Fix and commit:
git add .
git commit -m "Fix payment processing error"
Then merge the fix according to the team's workflow.
Conceptually:
main
|
A ---- B
\
C
|
hotfix/payment-error
|
v
main
Key Points
- Used for urgent production fixes.
- Usually created from the production branch.
- Should contain only the required fix.
- Merged back into relevant branches so the fix is not lost in future development.
Simple Comparison
| Branch | Main Purpose |
|---|---|
main |
Stable/production code |
feature/* |
Develop new functionality |
release/* |
Prepare a version for release |
hotfix/* |
Fix urgent production problems |
A common Gitflow-style structure is:
main
|
+------ hotfix/payment-error
|
develop
|
+------ feature/login
|
+------ feature/payment
|
+------ release/2.0
The exact branches depend on the organization's branching strategy.
2. What is the difference between a local branch and remote branch?
What is a Local Branch?
A local branch exists in your local Git repository on your computer.
Examples:
main
feature/login
feature/payment
View local branches:
git branch
Example output:
* main
feature/login
feature/payment
You can create a local branch using:
git switch -c feature/login
At this point, the branch exists only in your local repository until you push it.
What is a Remote Branch?
A remote repository is a Git repository hosted elsewhere, such as on GitHub or Azure Repos.
After you fetch remote information, Git keeps remote-tracking branches such as:
origin/main
origin/feature/login
Here:
origin
is usually the name of the remote repository.
And:
origin/main
is your local Git repository's remote-tracking reference representing the fetched state of the remote main branch.
View remote-tracking branches:
git branch -r
Example:
origin/main
origin/feature/login
View both:
git branch -a
Local Branch → Remote Branch
Suppose you create:
git switch -c feature/login
Initially:
Local
------
feature/login
Remote
------
Not available yet
Push it:
git push -u origin feature/login
Now conceptually:
Local Repository Remote Repository
---------------- -----------------
feature/login ---------> feature/login
push
The -u option sets the upstream tracking relationship, so later you can normally use:
git push
git pull
instead of specifying the remote and branch every time.
Local vs Remote Summary
| Local Branch | Remote Branch |
|---|---|
| Exists in your local repository | Exists in the remote repository |
| Used for your local development | Used for sharing/collaboration |
Example: feature/login |
Remote-tracking name: origin/feature/login |
Created with git branch / git switch -c |
Usually created on remote when pushed |
| Local commits remain local until pushed | Other developers can fetch/pull shared commits |
Key Points
- A local branch is the branch you work on locally.
- A remote branch is a branch stored in a remote repository such as GitHub or Azure Repos.
origin/mainis technically a remote-tracking branch in your local repository representing the last fetched state of the remote branch.git pushsends local commits to the remote repository.git fetchretrieves updated remote information without merging it into your current branch.git pullretrieves remote changes and integrates them into your current branch.- Local and remote branches can be connected through an upstream/tracking relationship.