Creating a new branch in Git is a straightforward process. You can do this using the Git command line interface. Here are the steps to create a new branch:
1. Open your terminal and navigate to your Git repository directory.
2. Check your current branch (optional):
git branch
3. Create a new branch:
You can create a new branch using the following command:
git branch <branch-name>
Replace <branch-name> with the desired name for your new branch.
4. Switch to the new branch:
After creating the branch, you need to switch to it using:
git checkout <branch-name>
Alternatively, you can combine steps 3 and 4 using:
git checkout -b <branch-name>
5. Verify that you are on the new branch (optional):
You can run the git branch command again to see a list of branches and confirm you are on the new branch.
6. Push the new branch to remote (optional):
If you want to push the new branch to the remote repository (like GitHub), use:
git push origin <branch-name>
That's it! You have successfully created and switched to a new branch in Git.