- Open Git Bash on your computer.
- Navigate to the local repository where you want to create the new branch. You can use the
cd
command to change directories. For example, if your repository is located inC:\Users\YourUsername\MyRepo
, you can run:
cd C:\Users\YourUsername\MyRepo
- Ensure that you are on the
main
branch or any other branch from which you want to create the new branch. You can use thegit branch
command to see the list of branches and the currently checked out branch. If you are not on the desired branch, you can switch to it using thegit checkout
command. For example, to switch to themain
branch, you can run:
git checkout main
- Once you are on the desired branch, create a new branch using the
git branch
command followed by the name you want to give to the new branch. For example, to create a branch named “new-feature”, run:
git branch new-feature
- After creating the branch, switch to the newly created branch using the
git checkout
command. For example, to switch to the “new-feature” branch, run:
git checkout new-feature
- At this point, you have created and switched to the new branch. You can now start making changes and committing them to the new branch.
- Once you have made the desired changes and commits, you can push the new branch to GitHub using the
git push
command. For example, to push the “new-feature” branch to the remote repository, run:
git push origin new-feature
CHECK VIDEO EXPLANATION