Merge the branches using pull request in GitHub

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)

Merge the branches

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

Merge the branches

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

Merge 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)

Merge the branches

Next we will use -d option to delete a branch 

Merge the branches

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

Merge the branches

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

Merge the branches

Next, click ‘Pull requests’

Merge the branches

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

Merge the branches

Click ‘compare: main’ dropdown that you see above

Merge the branches

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

Merge the branches

Click ‘Create pull request’

Merge the branches

Click ‘Create pull request’

Merge the branches

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

Merge the branches

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

Merge the branches

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

Merge the branches

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

Merge the branches

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’ 

Merge the branches

Click ‘Merge pull request’

Merge the branches

Click ‘Confirm merge’

Merge the branches

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

Click ‘Delete branch’

Merge the branches

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 

Merge the branches

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 

Merge the branches

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

Merge the branches

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

Merge the branches

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

Merge the branches

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

Merge the branches

We can delete this branch if required

Merge the branches

The branch is no longer seen

Merge the branches

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

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 1st Nov 2024