0% found this document useful (0 votes)
6 views

Branching and Merging (Web UI)

This document outlines a hands-on lab for using GitHub, focusing on creating a branch, committing changes, opening a pull request, and merging it into the main branch. It includes prerequisites, step-by-step instructions for each task, and a summary of the skills learned. The tutorial is authored by Malika Singla with contributions from Rav Ahuja.

Uploaded by

Simhadri Sevitha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Branching and Merging (Web UI)

This document outlines a hands-on lab for using GitHub, focusing on creating a branch, committing changes, opening a pull request, and merging it into the main branch. It includes prerequisites, step-by-step instructions for each task, and a summary of the skills learned. The tutorial is authored by Malika Singla with contributions from Rav Ahuja.

Uploaded by

Simhadri Sevitha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

5/6/23, 11:13 PM about:blank

Estimated time: 15 minutes

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.

2. Add a file to a branch


To add a file to your new branch, ensure that Child_Branch (or whatever name you gave your branch) is displayed in the Branch drop-down menu and
complete the following steps:

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.

The file is added to your child branch.

3. Open a pull request


about:blank 2/6
5/6/23, 11:13 PM about:blank
The file that you added to your child branch is not automatically added to the main branch. (You can check this by using the Branch drop-down menu to
go to the main branch; note that there is no testchild.py file in the file list):

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.

1. In Child_Branch, click the Compare & pull request button.

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.

4. Merge a pull request


To merge a pull request into a project, complete the following steps:

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:

Date Version Changed by Change Description


2023-01-30 0.5 Lavanya Rajalingam Fixed the link and minor corrections
2022-01-14 0.4 Rav Ahuja Added note about main branch
about:blank 5/6
5/6/23, 11:13 PM about:blank
Date Version Changed by Change Description
2020-07-16 0.4 Malika Singla Spell check, steps added
2020-07-14 0.3 Rav Ahuja Changed logo, updated title, intro, objectives, added Effort, Authors and Changelog
2020-07-13 0.2 Malika Singla Added to GitLab and made some formatting changes, added objectives, etc.
2020-06-30 0.1 Malika Singla Drafted initial version

about:blank 6/6

You might also like