Merge the branches using pull request in GitHub
What you will Learn:
- Create a branch and checkout in a single command
- Delete a branch
- Merge branches in remote GitHub
- Pull merged branch in local machine
Create a branch and checkout in a single command
This is tutorial 9 of Devops series. So far we have used a separate command to create a branch (git branch <branch-name>) and a separate command to check it out (git checkout <branch-name>).
We can also use a single command to perform both the operations. To do that, first of all, let us switch back to main branch (because right now we are in feature-landingpage branch)

Next, use ‘git checkout -b <branch-name>’ to create a branch as well as check it out

Notice above, we have switched to feature-dummy branch. The below command shows all the branches

Delete a branch
To delete a branch, first of all, let us switch back to main branch (because right now we are in feature-dummy branch)

Next we will use -d option to delete a branch

Also Check: Selenium Python Training
Merge branches in remote GitHub
As a best practice, when we want to merge 2 branches, we should do it using a pull request. So right now, we have 2 branches: main and feature-landingpage

We would like to take the changes from ‘feature-landingpage’ and then merge them into main branch.
Select ‘feature-landingpage’ from the above branch menu

Next, click ‘Pull requests’

Next, click ‘New pull request’ button that you see above. The below page would come up

Click ‘compare: main’ dropdown that you see above

Click ‘feature-landingpage’ that you see in the above dropdown. Wait for the page to refresh, below screen would come up

Click ‘Create pull request’

Click ‘Create pull request’

Notice the above message that says ‘W2AGit wants to merge 1 commit into main from feature-landingpage’.
Also, on the right hand side, you can see the ‘Reviewers’. You can add the desired set of people as reviewers and ask them to review your changes before proceeding to merging your changes with main branch

Also you can add a label (example, whether this is a bug fix or an enhancement etc)

Let us select ‘Enhancement’ and click somewhere outside the dropdown

Similarly you can add projects, milestones, link any issues etc

Now scroll down a bit on this page, you would see a message that this branch has no conflicts. You will also see a button ‘Merge pull request’

Click ‘Merge pull request’

Click ‘Confirm merge’

As seen above, merge is success. We also see a message that says ‘the feature-landingpage’ branch can be safely deleted.
Click ‘Delete branch’

We can click ‘Restore branch’ if we ever need to.
Go back to home repository page. You can now see ‘Merge pull request #1’ message

So this is how we merge branches in the remote GitHub repository.
Also Check: Selenium Training Online
Pull merged branch in local machine
The ‘git log’ command still does not show the information related to merged branch. The reason being, we haven’t yet pulled the repository from remote GitHub

Let us execute ‘git pull’ to bring the changes from remote to local

Now if you execute ‘git log’, you would see the merged branch info, see below

You can also execute ‘git log –oneline’ command to see the short log summary

Right now we see the branch ‘feature-landingpage’ in our local

We can delete this branch if required

The branch is no longer seen

So, this is how we merge the branches using pull request in GitHub and bring the changes to our local.
So we have completed the fundamentals of Git-GitHub.
We would next start with installation of Linux Ubuntu virtual machine on Oracle VM Virtual box.
Thank you for reading!
Also Check: API Testing Training
