Merge
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.
Git Command
To merge a branch into the local main
branch:
git checkout main # Switch to the main branchgit merge branch_name
For example, the following merges a branch called feature_test
branch to the main
branch:
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.com
is 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.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Git on Codecademy
- Course
Learn Git & GitHub
Use our beginner friendly Git course to integrate Git and GitHub and manage versions of your projects using Git branches.With CertificateBeginner Friendly4 hours - Course
Learn the Command Line
Learn about the command line, starting with navigating and manipulating the file system, and ending with redirection and configuring the environment.With CertificateBeginner Friendly4 hours