Branching & Merging in Git
Git·4 min read·Jan 1, 2025
In Git, a branch is a lightweight and isolated line of development that allows developers to concurrently work on new features, bug fixes, or experiments without affecting the main codebase.
The master branch
The master branch, nowadays called the main branch, is the default main line of development in a Git repository.
It is automatically created by Git when initializing a new repository.
It contains the production-ready code that represents the latest stable released version of the software.
When a set of features or bug fixes are deemed ready for release, the temporary branches they were developed on are then merged (or integrated) into the main branch, so that the new code becomes part of the main branch's history.
This history provides a clear and organized record of the project's evolution over time, and represents the chronological history of stable releases and major changes in the project.
Note: While master and main are the two most common names for this branch, Git doesn't enforce a specific name.
Listing existing branches
To get the list of existing branches, you can use the git branch command without arguments:
$ git branch development* masterWhere the branch marked with an asterisk * represents the current branch in use, referred to as the checked out branch.
Creating a new branch
In essence, a branch is a type of "sandbox" environment to which you can make changes without affecting other branches.
Unlock the Build CLI Apps in JavaScript & Node.js module
Learn how to build, integrate, and safeguard scalable CLI tools, scripts, and apps with JavaScript, Node.js, npm, and Git.
You get immediate access to:
- 45 focused lessons across JavaScript, Node.js, npm, and Git
- 17 real-world projects with commented solutions
- Ongoing updates to this bundle
- Lifetime access to this bundle