Git Branch Basics
What is a Git Branch?
A Git branch is a lightweight, movable pointer to a specific commit in the repository's history. It represents an independent line of development, allowing developers to work on different features or fixes simultaneously without interfering with each other.
Branch Workflow
gitGraph
commit
branch feature
checkout feature
commit
commit
checkout main
merge feature
Types of Branches
Branch Type |
Purpose |
Example |
Main/Master |
Primary development branch |
main |
Feature Branch |
Develop new features |
feature/login |
Hotfix Branch |
Quick production fixes |
hotfix/security-patch |
Release Branch |
Prepare for new release |
release/v1.2.0 |
Creating Branches in Git
To create a new branch in Git, use the following command:
## Create and switch to a new branch
git checkout -b feature/new-functionality
## Alternative method
git branch feature/new-functionality
git checkout feature/new-functionality
Branch Management Basics
- List all local branches:
git branch
- List remote and local branches:
git branch -a
- Check current branch:
git branch --show-current
By understanding these Git branch basics, developers can effectively manage code development using LabEx's recommended version control practices.