1 00:00:00,070 --> 00:00:10,669 In this video, you will learn how to create and 2 00:00:10,669 --> 00:00:13,999 merge a branch using the GitHub web interface. 3 00:00:13,999 --> 00:00:18,619 A branch is a snapshot of your repository to which you can make changes. 4 00:00:18,619 --> 00:00:23,560 It is a copy of the master branch and can be used to develop and test changes to the 5 00:00:23,560 --> 00:00:29,619 workflow before merging it back to the master branch. In Git and GitHub, there is a main 6 00:00:29,619 --> 00:00:31,169 branch. 7 00:00:31,169 --> 00:00:35,829 The main branch which is called Master, is the one with deployable code 8 00:00:35,829 --> 00:00:39,010 and the official working version of your project. 9 00:00:39,010 --> 00:00:44,090 It is meant to be stable and it is always advisable never to push any code that is not 10 00:00:44,090 --> 00:00:46,260 tested to master. 11 00:00:46,260 --> 00:00:51,620 Many times, we want to make changes to the code and workflow in the master branch. 12 00:00:51,620 --> 00:00:54,390 That is when we create a copy of the Master branch. 13 00:00:54,390 --> 00:00:56,739 Let’s call it Child Branch. 14 00:00:56,739 --> 00:01:02,660 We will then create a copy of the workflow to the child branch in the child branch, changes 15 00:01:02,660 --> 00:01:04,640 and experiments are done. 16 00:01:04,640 --> 00:01:09,890 We will build and make edits, test the changes and when we are satisfied with the changes 17 00:01:09,890 --> 00:01:14,729 we will merge it back to the master branch where we prepare the model for deployment. 18 00:01:14,729 --> 00:01:20,360 We can see that all of this is done outside of the main branch and until we merge, changes 19 00:01:20,360 --> 00:01:24,020 will not be made to the workflow before we branched. 20 00:01:24,020 --> 00:01:29,009 To ensure that changes done by one member, does not impede or affect the flow of work 21 00:01:29,009 --> 00:01:34,530 of other members, multiple branches can be created and merged appropriately to master 22 00:01:34,530 --> 00:01:38,229 after the workflow is properly tested and approved. 23 00:01:38,229 --> 00:01:42,290 To create branches in GitHub, let’s look at this repository. 24 00:01:42,290 --> 00:01:44,799 There is currently one branch in the repository. 25 00:01:44,799 --> 00:01:49,590 I want to make some changes, but I don’t want to alter the master in case something 26 00:01:49,590 --> 00:01:50,860 goes wrong. 27 00:01:50,860 --> 00:01:52,759 We will create a branch. 28 00:01:52,759 --> 00:01:57,180 To do that, we will click the drop-down arrow and create a new branch. 29 00:01:57,180 --> 00:02:01,500 Let's name it - child branch and then we will click enter. 30 00:02:01,500 --> 00:02:06,759 The repository now has two branches, the Master and the Child branch. 31 00:02:06,759 --> 00:02:11,810 You can check this by selecting Child branch in the Branch selector drop-down list. 32 00:02:11,810 --> 00:02:16,000 Whatever was in the Master branch was copied to the child branch. 33 00:02:16,000 --> 00:02:21,850 But we can add files in the child branch without adding any files to the master branch. 34 00:02:21,850 --> 00:02:27,460 To add a file, make sure Child branch is selected in the branch selector drop-down list. 35 00:02:27,460 --> 00:02:33,740 Click on create new file. In the space provided, name the file - we will name it 36 00:02:33,740 --> 00:02:37,740 testchild.py and then we will add a few lines of code. 37 00:02:37,740 --> 00:02:41,690 We will print the statement – Inside child branch. 38 00:02:41,690 --> 00:02:46,440 At the bottom of the screen, we will see a section called Commit new file. 39 00:02:46,440 --> 00:02:51,420 Commit messages are very important as it helps to keep track of the changes that were made. 40 00:02:51,420 --> 00:02:56,300 It is important to add a descriptive commit message so that other team 41 00:02:56,300 --> 00:02:57,300 members can understand it. 42 00:02:57,300 --> 00:02:59,330 Here we will add a commit message, 43 00:02:59,330 --> 00:03:03,220 Create testchild.py, then we will commit the new file. 44 00:03:03,220 --> 00:03:06,400 The file gets added to only the child branch. 45 00:03:06,400 --> 00:03:11,270 We can check this by going to the master branch by clicking ‘master’ from the Branch selector 46 00:03:11,270 --> 00:03:17,440 menu and here we can see that the new file is not added to the master branch. 47 00:03:17,440 --> 00:03:22,200 After we have created the new file, tested and made sure that is up to standards. 48 00:03:22,200 --> 00:03:27,610 We then want to merge the changes in the child branch to reflect in the master branch. 49 00:03:27,610 --> 00:03:33,870 To merge the changes, we will first have to create a pull request, also known as a PR. 50 00:03:33,870 --> 00:03:39,330 A pull request in simple terms is a way to notify other team members of your changes 51 00:03:39,330 --> 00:03:46,230 and edits and ask them for review so they can be pulled or merged into the master branch. 52 00:03:46,230 --> 00:03:50,080 Pull requests are the heart of collaboration on GitHub. 53 00:03:50,080 --> 00:03:55,570 When you open a pull request, you’re proposing your changes and requesting that someone review 54 00:03:55,570 --> 00:04:00,950 and pull in your contribution and merge them into the target branch. 55 00:04:00,950 --> 00:04:05,330 Pull requests show the differences of the content from both branches. 56 00:04:05,330 --> 00:04:10,380 To open a pull request and see the differences between the branches, click on the Compare 57 00:04:10,380 --> 00:04:12,430 and pull request button. 58 00:04:12,430 --> 00:04:16,940 If you scroll down to the bottom of the screen, you will see something like this that shows 59 00:04:16,940 --> 00:04:19,510 you the difference between both branches. 60 00:04:19,510 --> 00:04:24,810 As you can see on the screen it shows that one file has changed and the file has two 61 00:04:24,810 --> 00:04:30,320 additions, which are the two lines we added to the file and 0 deletions. 62 00:04:30,320 --> 00:04:32,930 We will now create the pull request. 63 00:04:32,930 --> 00:04:37,080 Add the title and an optional comment for the pull request. 64 00:04:37,080 --> 00:04:40,470 Click Create Pull request to create the pull request. 65 00:04:40,470 --> 00:04:45,340 You can assign team members to review and approve pull requests. 66 00:04:45,340 --> 00:04:50,820 On the next page you will see this image. If you are okay with the changes, click on Merge 67 00:04:50,820 --> 00:04:56,070 pull request and click confirm. You will get a confirmation that the pull request has been 68 00:04:56,070 --> 00:04:58,100 successfully merged. 69 00:04:58,100 --> 00:05:03,640 You can now delete the branch if you no longer need to make any edits or add new information. 70 00:05:03,640 --> 00:05:08,290 Now, the child branch has completely merged with the Master branch. 71 00:05:08,290 --> 00:05:13,460 You can check the Master branch and we can now see it contains the 72 00:05:13,460 --> 00:05:14,460 testchild.py file. 73 00:05:14,460 --> 00:05:19,930 You should now be familiar with how to create and merge branches using the web interface.