How to create a new branch on github
To create a new branch on 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.
- Replace
- 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 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.
- Replace
- 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 origin <branch-name>
Tips:
- Make sure to replace
<branch-name>
with the actual name you want to give your new branch. - You can also use
git branch -a
to list all branches, including remote branches. - If you want to create a new branch from a specific commit, you can use
git branch <branch-name> <commit-hash>
. - You can also use
git checkout -b <branch-name>
to create a new branch and switch to it in one step.