Creating a pull request (PR) and merging a subbranch with the main branch on GitHub involves several steps. Here’s a detailed guide:
1. **Prepare Your Branch**
Ensure that you have committed and pushed your changes to the subbranch that you want to merge into the main branch.
1. **Switch to Your Subbranch:**
“`bash
git checkout your-subbranch
2. **Commit Your Changes:**
“`bash
git add .
git commit -m “Your commit message”
3. **Push Your Subbranch to GitHub:**
“`bash
git push origin your-subbranch
2. **Create a Pull Request**
1. **Go to Your Repository on GitHub:**
Navigate to the repository where you want to create the pull request.
2. **Open the Pull Requests Tab:**
Click on the “Pull requests” tab located near the top of the page.
3. **Click on “New Pull Request”:**
You’ll find this button near the top right of the page.
4. **Choose the Base and Compare Branches:**
– **Base branch:** This is usually `main` or `master` (the branch you want to merge into).
– **Compare branch:** This is your subbranch (the branch with your changes).
5. **Review Your Changes:**
GitHub will show a comparison of the changes between the base and compare branches. Review these changes to ensure everything is as expected.
6. **Create the Pull Request:**
– **Title:** Provide a clear and concise title for your pull request.
– **Description:** Add a description that provides context about what your pull request is doing and why the changes are being made.
– **Click “Create pull request”** to submit it.
3. **Review and Merge the Pull Request**
1. **Review the Pull Request:**
– Team members or collaborators will review the pull request. They might comment, request changes, or approve it.
2. **Address Feedback:**
If there are any comments or requested changes, update your branch accordingly and push the changes:
“`bash
git add .
git commit -m “Address feedback”
git push origin your-subbranch
3. **Merge the Pull Request:**
– Once the pull request is approved and ready to be merged, you’ll see a “Merge pull request” button.
– **Click “Merge pull request”** to merge your changes into the base branch.
– Confirm the merge if prompted.
4. **Delete the Branch (Optional):**
After merging, you may want to delete the subbranch to keep your repository clean. GitHub will prompt you with an option to delete the branch after the merge. Alternatively, you can delete it manually:
“`bash
git branch -d your-subbranch
git push origin –delete your-subbranch
4. **Sync Your Local Repository**
Finally, make sure your local main branch is up to date:
“`bash
git checkout main
git pull origin main
“`