In Git, completed changes made to a branch can be merged to the
main branch. When collaborating on a remote repository, a pull request will need to be opened in order to do this. Anyone with push access to the repository can complete the merge.
To merge a branch into the local
git checkout main # Switch to the main branchgit merge branch_name
For example, the following merges a branch called
feature_test branch to the
git checkout maingit merge feature_test
Merging a Pull Request on GitHub
For information on how to open a pull request, see the Pull Requests section.
On the GitHub repository page, click the “Pull requests” tab at the top.
In the “Pull Requests” list, choose the pull request that you’d like to merge.
Depending on the merge options enabled for your repository, you can:
Merge all the commits into the base branch by clicking Merge pull request. If the Merge pull request option is not shown, then click the merge drop down menu and select Create a merge commit.
Squash the commits into one commit by clicking the merge drop down menu, selecting Squash and merge and then clicking the Squash and merge button.
Rebase the commits individually onto the base branch by clicking the merge drop down menu, selecting Rebase and merge and then clicking the Rebase and merge button.
If prompted, type a commit message, or accept the default commit message.
If you have more than one email address associated with your GitHub account, click the email address drop-down menu and select the email address to use as the Git author email address. Only verified email addresses appear in this drop-down menu. If you enabled email address privacy, then
<username>@users.noreply.github.comis the default commit author email address.
Click Confirm merge, Confirm squash and merge, or Confirm rebase and merge.
(Optional) Last but not the least, delete the feature branch. This keeps the list of branches in your repository nice and tidy.