Open In App

Git – Create a Branch From Another Branch

Last Updated : 15 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Git is distributed version control system used for tracking changes in source code during software development.

  • Git is designed to handle everything from small to very large projects with speed and efficiency.
  • It allows multiple developers to work on the same codebase concurrently.
  • Git stores data in a series of snapshots, which represent the state of the code at a specific point in time.

In this article, we are going to create a new branch from an existing branch in Git. This is a useful feature if you want to work on a new feature or bug fix that is related to the existing branch. The new branch will have the same commit history as the existing branch but you can make changes to the new branch without affecting the existing branch.

Step-by-Step Implementation

1. Ensure that you have checked out the branch from which you want to create the new branch. You can use the git checkout command to switch to the branch.

git checkout existing-branch

2. Use the git branch command to create a new branch.

git branch new-branch

3. Switch to the new branch using the git checkout command.

git checkout new-branch

4. Make changes to the new branch as needed. You can commit your changes to the new branch using the git commit command.

git commit -m "Commit message"

5. If you want to push the new branch to a remote repository, use the git push command.

git push -u origin new-branch

Example

Step 1: Open Git Bash

 

Step 2: Navigate to Git Directory

 

Step 3: Create a Branch and Switch to it

 

Step 4: View Branch List

 

Step 5: Switch Branch

 


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads