Tutorial 9: Merge Branch

What you will Learn:

Create a branch and checkout in a single command

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 Branch

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

Merge Branch

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

Merge Branch

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 Branch

Next we will use -d option to delete a branch

Merge Branch

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-landing page

Merge Branch

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 Branch

Next, click ‘Pull requests’

Merge Branch

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

Merge Branch

Click ‘compare: main’ dropdown that you see above

Merge Branch

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

Merge Branch

Click ‘Create pull request’

Merge Branch

Click ‘Create pull request’

Merge Branch

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 Branch

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

Merge Branch

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

Merge Branch

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

Merge Branch

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 Branch

Click ‘Merge pull request’

Merge Branch

Click ‘Confirm merge’

Merge Branch

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

Merge Branch

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 Branch

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

Merge Branch

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

Merge Branch

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

Merge Branch

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

Merge Branch

We can delete this branch if required

Merge Branch

The branch is no longer seen

Merge Branch

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!

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 - 10000 RS/149 USD
Attend All Live courses in just 10000 rs / $149 - offer ends 25th April 2024