While pulling the projects from GitHub, it is always important to select the correct base branch in order to keep the valuable work before merging it. GitHub allows developers to change the base branch during the pull request of the project. Don’t know how to perform it? stay tuned to this blog!
The outcomes of this guide are:
How to Change the Base Branch During a Pull Request?
To change the base branch during a pull request, follow the below-given steps.
Step 1: Move to Project Directory
Initially, move to the desired project directory using the “cd” command:
Step 2: List Files
After that, list and check the content of the current repository by running the “ls” command:
According to the above output, the “demo1” repository contains two files “file2.txt” and “newfile.txt” respectively.
Step 3: Open the File
Execute the “start” command to edit changes in the existing file:
Step 4: Track the File
Now, add the updated files into the staging area through “the git add” command:
Step 5: Push Project File
Finally, push the project with added changes to the remote host:
In our case, the project has been pushed to the master remote branch.
Step 6: Compare and Pull the Request
After that, navigate to the GiHub, and you will see the pushed project. Hit the “Compare & pull request” button and continue:
Step 7: Change the Base Branch
From the appeared interface, click on the below-highlighted icon and list all the existing branches. Then, change the base branch of the project from the drop-down menu:
As in our scenario, we are switched from the “master” to the “beta” branch.
Step 8: Verify the Change
As you can see, the base branch has been switched to “beta” as shown in the following image. Then, click on the below-highlighted button and create the pull request:
How to Merge Pull Requests in GitHub?
After comparing the pull request, users need to merge it. For that purpose, check out the following steps.
Step 1: Merge the Pull Request
For merging the pull request, scroll down the create pull request page and click on the “Merge pull request” button:
Step 2: Check Pull Request
Now, check whether the pull request has been merged or not. It can be seen below:
For changing the base branch during a pull request, open Git bash and move to the project directory. List the content of the directory and apply some changes in the files using the “start” command. After that, push the project to GitHub. Next, open GitHub and press the “Compare & pull request” button. Finally, change the base branch. This post has illustrated the method to change the base branch of a pull request in Git and the merging procedure.