GitHub How To Merge The Branch To Master?

509 Views
0 rating based on 0 reviews

When I started to use Git, one of the biggest blockers I had was how to merge a branch into master. If you use Git, you know that it is not easy, and many beginners get confused when they look for help on the internet. This guide will show you the most common way of merging a branch into master.

Merge the branch to master

When it comes to a group of people working together on a project sharing their ideas and views, GitHub is the best platform to do that. GitHub is the place where all types of source codes are stored and shared and people can also view the uploaded works of users.

When you have permission to add a comment or edit in a particular file or folder, it can be stored in another branch other than the main(master) branch. You can easily merge the branch into master if there are no conflicts that may change or harm the main branch.

When people in your team submit their ideas to edit, add, or make changes to the project, you can always tell them to create a branch file in the repository by giving them access and as a leader, you can review their work and if their ideas are acceptable you can take steps to merge them in the main file to overall improve the entire project.  You will need to follow these steps to successfully merge into main.

Before you get started

You must have the authority and approval of your team to be able to merge the branch files. Otherwise, you will not have access to make changes to the master(main) branch. To merge to master, follow these steps:

  1. Log in to your GitHub account.
  2. Got to “my repository” in the User options on the bottom right side of the webpage.
    User options
  3. Select the repository in which the branch file has been created or the branch in which the people from the team uploaded their ideas.
    the branch file
  4. You can also edit your branch section if you have any new ideas to merge and apply commit changes.
    Editing files
  5. Go to the repository, there a pop-up “Compare and Pull request” will show. Click it.
    request pop-up
  6. If the branch can merge, you will see a green label saying “able to merge”. You can merge the branch without any problems.
    Merge confirmation
  7. Click “create pull request [labeled green]” on the bottom right of the webpage.
    Pull request
  8. If the branch has no conflicts with the base branch then the “Merge pull Request” will pop up.
    Confirmation of no conflicts
  9. Click the “Merge pull request [labeled green]” button to merge the changes into the main branch.
  10. Click “Confirm merge” when it appears.
    The Merge confirmation
  11. You will be provided the option to delete the branch, since its changes have been incorporated, select the “Delete branch” button in the purple box if you are sure that there will be no new ideas from the branch provided by a team member. You can also keep the branch as your teammates can incorporate more ideas or code for you to merge in the future.
    Delete confirmation
  12. Select the “<>Code” icon and you will see that the branch has been merged to master. The master branch will be available for the team to view what changes have been made as a team.
    Updated main branch

Summary: GitHub how to merge the branch to master

  • If a repository has any protected branches, you cannot push commits to it until your pull request is reviewed and approved.
  • You can commit the changes locally, pull from the remote repository to sync with your team members' work, fix any conflicts that arise, and then push those changes.
  • If you are working in a forked repository, you can sync your fork's default branch with the upstream repository's default branch or any of its other branches.
  • The primary reason for creating a new branch is to isolate your work from other people working on the same project.
  • Once you have committed your changes to GitHub and let others know about them, they can review your changes and pull them into their own local copy of the project.
  • After you merge a pull request into the default branch of the upstream repository, GitHub deletes the head branch of the pull request.
  • Takeaway: GitHub is an important source code control platform for developers.