Git
Git Tutorial for Beginners with Examples
Install Git
Add Local Project to Remote Git Repository
How to Clone a Project from a Remote Git Repository
Create a New Branch in Git
Switching Branches in Git
How to Push Code from Local to Remote Repository
Pushing a New Local Branch to a Remote Git Repository
Deleting a Git Branch Both Locally and Remotely
Restoring a Deleted Git Branch
Switching to a Different Branch Without Committing Changes in Local Git Repository
Git Stash Revert: How to Restore Stashed Changes in Git
Creating a Git Pull Request
Cancel a Git Pull Request
Tags in Git
Git Commands for Beginners
Generating a Personal Access Token on GitHub
Update the Local Branch with the Latest Code Changes from the Remote Branch
Compare Two different Git Branches in Visual Studio Code
Create a New Branch in Git
- Last updated Apr 25, 2024
A branch represents a separate line of development. When you start to work on a new feature, you usually create a new branch off master branch or any other branch which is later merged back to the main branch.
Follow these steps to create a new branch in Git:
- First, make sure you are on the correct branch from which you want to create a new branch.
- Use the 'branch' command, followed by the new branch name, to create a new branch:
- After creating a new branch, the next step is to switch to the newly created branch by using the 'checkout' command followed by the branch name:
git branch new_branch_name
Replace "new_branch_name" with the name you want for your new branch.
git checkout new_created_branch_name
Replace 'new_created_branch_name' with the name of the newly created branch to which you want to switch.
You can also create and switch to a new branch using a single command. The 'checkout -b' command allows you to create and switch to a new branch in one go:
git checkout -b new_branch_name