To create and manage branches in GitHub, you can use the following steps:
1. **Create a New Branch**: On the GitHub repository page, click on the "Branch" dropdown menu, located above the file list. Type in a name for your new branch in the text box and click on the "Create branch" button. This will create a new branch based on the current branch or the selected branch.
2. **Switch to a Branch**: To switch to a different branch, use the branch dropdown menu on the repository page, select the desired branch, and click on it. This will display the files and content specific to that branch.
3. **Create a Branch Locally**: If you want to create a branch locally and then push it to GitHub, you can use the following commands in your terminal or command prompt:
- To create a new branch:
git branch <branch-name>
Replace `<branch-name>` with the name you want to give to your branch.
- To switch to the new branch:
git checkout <branch-name>
Replace `<branch-name>` with the name of the branch you just created.
These commands create a new branch and switch to it in your local repository.
4. **Push a Branch to GitHub**: If you have created a branch locally and want to push it to GitHub, use the following command:
git push origin <branch-name>
Replace `<branch-name>` with the name of the branch you want to push.
This command pushes your local branch to the remote repository on GitHub, making it available to others.
5. **Merge Branches**: To merge changes from one branch into another, you can use the steps mentioned earlier for merging branches using the `git merge` command. After merging the branches locally, you can push the merged changes to GitHub using `git push origin <branch-name>`.
6. **Delete a Branch**: To delete a branch in GitHub, go to the repository's page, click on the "Branch" dropdown menu, select the branch you want to delete, and click on the trash can icon next to it. Confirm the deletion in the dialog box that appears.
To delete a branch locally, use the following command:
git branch -d <branch-name>
Replace `<branch-name>` with the name of the branch you want to delete.
Deleting a branch removes it from both your local repository and the remote repository on GitHub.
By following these steps, you can create, switch, push, merge, and delete branches in GitHub. Branching allows you to work on different features or bug fixes in isolation, facilitating parallel development and code management.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc