Sitemap
Sankalp Salve

Sankalp Salve

Tech, history, and physics enthusiast. Writing stories that explore the evolution of technology, the impact on society, and the fundamental laws of our universe

Git-Branch

2 min readMar 21, 2023

Git branching is one of the most powerful and essential features of Git, a popular version control system. It enables developers to create multiple isolated copies of the codebase, work on different features, and merge them back into the main branch when they are ready. Git branching is a fundamental concept that every developer should understand to effectively manage their projects.

A branch in Git is essentially a lightweight pointer to a specific commit, which represents a snapshot of the codebase at a given point in time. When you create a new branch, Git creates a new pointer that points to the same commit as the current branch. You can then make changes to the codebase in the new branch without affecting the original branch. This is incredibly useful for developing new features, bug fixes, or experimental changes without disrupting the main codebase.

To create a new branch, you can use the git branch command followed by the name of the new branch. For example, to create a new branch named "new-feature", you would run the following command:

git branch new-feature

Once you have created a new branch, you can switch to it using the git checkout command followed by the name of the new branch. For example, to switch to the new-feature branch, you would run the following command:

git checkout new-feature

Now you can make changes to the codebase in the new branch without affecting the original branch. You can commit your changes as usual using the git commit command.

Get Sankalp Salve’s stories in your inbox

Join Medium for free to get updates from this writer.

When you are ready to merge your changes back into the original branch, you can use the git merge command. This command takes the changes made in the current branch and applies them to the target branch. For example, to merge the changes from the new-feature branch into the main branch, you would run the following command while on the main branch:

git merge new-feature

Git branching also allows you to visualize the history of your codebase and track the progress of different features. You can use the git log command to see a list of all the commits in the current branch, and the git log --oneline --graph command to see a graphical representation of the commit history, including all branches and merges.

In addition to creating new branches, you can also delete branches that are no longer needed using the git branch -d command followed by the name of the branch. For example, to delete the new-feature branch after merging it into the main branch, you would run the following command:

git branch -d new-feature

In conclusion, Git branching is an essential concept that enables developers to work on multiple features simultaneously, without disrupting the main codebase. Git branching helps to keep the codebase organized, and it makes it easier to track progress and collaborate with other developers. If you are new to Git, learning how to create, switch, and merge branches is a great place to start.

--

--

Sankalp Salve
Sankalp Salve

Written by Sankalp Salve

Tech, history, and physics enthusiast. Writing stories that explore the evolution of technology, the impact on society, and the fundamental laws of our universe