Branching and Merging (Web UI)
Branching and Merging (Web UI)
Objectives
After completing this lab you will be able to:
1. Create a branch
2. Commit changes to a child branch
3. Open a pull request
4. Merge a pull request into the main branch
Prerequisites
This hands-on lab requires you to have created a GitHub account and added a project to it, as covered in the Getting started with GitHub lab.
NOTE: In the past the default branch in your GitHub repo used the name master. Effective Oct 1. 2020, all new GitHub repositories use the
more inclusive term main as the name of the default branch instead of master.
1. Create a branch
You can create or delete branches using your repository’s GitHub web page. To add a branch to your repository, complete the following steps:
1. Go to you repository’s main page. Note that when you created your repository, the main branch was created for you:
2. At the top of the file list, locate the Branch drop-down menu. (By default, the menu displays Branch: main.) Click the drop-down menu, type the
name of the branch you want to create, and press Enter on your keyboard.
Your repository now has two branches: Main and Child_Branch. You can click the drop-down menu to see your branches.
about:blank 1/6
5/6/23, 11:13 PM about:blank
Any files that were in the main branch have now been copied to Child_Branch. Note that when you add or edit a file in Child_Branch, that change will
not automatically be made in the main branch.
1. Click Add file > Create new file to create a file in the repository.
2. Type a name and extension for the file – for example, testchild.py – and add the following lines to the body of the new file:
3. Scroll to the bottom of the page, add a description of the file you are about to add (note that the description is optional), and click Commit.
You can also compare the two branches and open a pull request, which will enable you to copy the changes that you’ve made in the child branch – in this
case, adding a new file – to the main branch.
2. Scroll to the bottom of the page and note that there is 1 changed file listed.
3. Scroll up and note that GitHub is comparing the main and Child_Branch branches and that there are no conflicts between the two. Optionally, you
can add a comment to the pull request. Click Create pull request.
about:blank 3/6
5/6/23, 11:13 PM about:blank
The pull request is created and can now be merged by a repository administrator.
1. Click the Pull requests tab. A list of pending pull requests is displayed.
2. Click the pull request that you want to merge into the main project. If you are satisfied with the changes, click Merge pull request to accept the
pull request and merge the updates. (You can add a comment if you choose.)
3. When you click Merge pull request, a Confirm merge button is displayed. Click that button to complete the merge.
about:blank 4/6
5/6/23, 11:13 PM about:blank
The pull request has now been merged successfully. Note that you can delete the child branch because your changes have been incorporated into the
main branch.
Check the list of files in the main branch to confirm that it now includes the file that you added in the pull request.
Summary
Congratulations! You’ve now learned how to create a branch, edit and commit changes in that branch, open a pull request, and merge the pull request into
your main project. We encourage you to continue to experiment with branches and pull requests to become more familiar with the concepts and processes.
Tutorial details
Author:
Malika Singla
Other contributor:
Rav Ahuja
Changelog:
about:blank 6/6