How to create a new branch in Git?


by deron , in category: Third Party Scripts , 6 months ago

How to create a new branch in Git?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by tressie.damore , 6 months ago


To create a new branch in Git, you can follow these steps:

  1. Open your terminal or command prompt.
  2. Navigate to the directory of your Git repository using the 'cd' command.
  3. Ensure you are on the main branch by executing the command git branch. The * beside the main branch indicates that it is the active branch.
  4. Execute the command git checkout -b
  5. Git will switch to the newly created branch, and you can start working on it.

Alternatively, you can create a branch from a specific commit or another branch by using the following command:

git checkout -b <new-branch-name> <commit-or-branch-name>

Again, replace <new-branch-name> with the desired name for your new branch, and <commit-or-branch-name> with the commit hash or branch name you want to base your new branch on.

That's it! You have now created a new branch in Git.