menu

DEEP DIVE INTO

Git

Topic:Create Branch

menu

To create a new branch in Git, you can use the git branch command followed by the name you want to give to the new branch.

Here's the basic syntax for creating a branch:

bashgit branch 

Replace branch-name with the name you want to give to your new branch. Here's an example of creating a branch named "feature-branch":

bashgit branch feature-branch

The above command will create a new branch named "feature-branch" that starts from the commit you're currently on.

However, it's important to note that this command only creates the branch; it doesn't switch you to the newly created branch.

info

To switch to the new branch immediately after creating it, you can use the git checkout command like this:

bashgit checkout feature-branch

In more recent versions of Git (since 2.23), you can combine the branch creation and checkout into a single command using the -b option of git checkout:

bashgit checkout -b feature-branch

This will both create and switch to the "feature-branch" in one step.

1280 x 720 px