How to create new branch in github
To create a new branch in GitHub, you can follow these steps:
Using the GitHub Web Interface:
- Log in to your GitHub account and navigate to your repository.
- Click on the "Code" button to view the repository's code.
- Click on the "Branch" dropdown menu at the top of the page.
- Click on "New branch" from the dropdown menu.
- Enter a name for your new branch in the "Branch name" field. You can also choose a base branch from the dropdown menu.
- Click on the "Create branch" button to create the new branch.
Using the Command Line:
- Open a terminal or command prompt and navigate to your local repository directory.
- Use the following command to create a new branch:
git branch <branch-name>
- Replace
<branch-name>
with the name you want to give your new branch. - To switch to the new branch, use the following command:
git checkout <branch-name>
- To push the new branch to GitHub, use the following command:
git push -u origin <branch-name>
Using Git Bash:
- Open Git Bash and navigate to your local repository directory.
- Use the following command to create a new branch:
git branch <branch-name>
- Replace
<branch-name>
with the name you want to give your new branch. - To switch to the new branch, use the following command:
git checkout <branch-name>
- To push the new branch to GitHub, use the following command:
git push -u origin <branch-name>
Tips:
- You can also use
git checkout -b <branch-name>
to create a new branch and switch to it in one step. - Make sure to replace
<branch-name>
with a unique and descriptive name for your new branch. - You can also use
git branch --list
to list all the branches in your repository, including the new one you just created. - If you want to create a new branch from a specific commit, you can use
git branch <branch-name> <commit-hash>
.