0 1 00:00:00,420 --> 00:00:06,480 So in the last few lessons, we looked at implementing source control locally using the command line, as 1 2 00:00:06,480 --> 00:00:10,550 well as using Xcode and, also, remotely using GitHub. 2 3 00:00:10,800 --> 00:00:17,520 So, now I want to take you a little bit further and I want to talk about collaboration using remote repositories 3 4 00:00:17,640 --> 00:00:25,800 and GitHub, because this is one of the best ways to start working in a team of programmers and to contribute 4 5 00:00:26,070 --> 00:00:28,670 your skills to open source projects. 5 6 00:00:28,680 --> 00:00:34,560 So we've seen all of these four areas: the working directory, the staging area, the local repository, as 6 7 00:00:34,560 --> 00:00:36,300 well as the remote repository. 7 8 00:00:36,480 --> 00:00:40,120 And you should be pretty familiar with all four of these areas by now. 8 9 00:00:40,380 --> 00:00:48,400 Now, in the next scenario, let's shift over to just look at the local and remote repository that you own. 9 10 00:00:48,420 --> 00:00:50,610 So let's say that Angela, 10 11 00:00:50,610 --> 00:00:57,750 so myself, I own this repository. I created it locally, and then I pushed it to my remote repository on 11 12 00:00:57,750 --> 00:00:58,890 GitHub. 12 13 00:00:58,890 --> 00:01:04,330 Now, let's say that I have an evil twin who's called, 13 14 00:01:04,730 --> 00:01:07,210 I don't know, Bad-ngela. That's a terrible name. 14 15 00:01:07,380 --> 00:01:12,150 Let's say that she also wanted to make changes to my repository. 15 16 00:01:12,150 --> 00:01:18,840 She's looking at my code base and, you know, she wants to add some features or fix some bugs or do something. 16 17 00:01:19,350 --> 00:01:27,600 Now, because I own this remote repository over here, in order for her to work on it, she could make a copy 17 18 00:01:27,600 --> 00:01:30,770 of it that exists on her GitHub account. 18 19 00:01:30,990 --> 00:01:38,550 So remember, this is different from git clone. Git clone is just grabbing the entirety of the repository, 19 20 00:01:39,060 --> 00:01:42,660 and then cloning it to your local work environment. 20 21 00:01:42,660 --> 00:01:48,360 Now, in this case, we're basically just copying a repository that's hosted on GitHub and we're keeping 21 22 00:01:48,360 --> 00:01:52,790 the copy under our own GitHub account where we can make changes to it. 22 23 00:01:53,070 --> 00:01:56,920 So this in terms of GitHub lingo is called forking. 23 24 00:01:57,030 --> 00:02:04,350 Now, once you fork a remote repository, then you now own it. You have full permissions to do whatever 24 25 00:02:04,350 --> 00:02:07,870 it is that you like with this copy of the repository. 25 26 00:02:07,890 --> 00:02:15,000 Because as you can imagine, it would be pretty crazy if everybody could modify your source code on all 26 27 00:02:15,000 --> 00:02:21,030 of your open source repositories because, you know, it would lead to, maybe, amateurs changing all sorts 27 28 00:02:21,030 --> 00:02:28,230 of things that you don't want them to or, you know, people making features that are incompatible with 28 29 00:02:28,230 --> 00:02:29,690 what you've got already. 29 30 00:02:29,700 --> 00:02:35,430 Basically, you would only give people who you have a trusting relationship with, write access to your 30 31 00:02:35,430 --> 00:02:36,580 remote repository. 31 32 00:02:36,600 --> 00:02:43,170 So, say, if you work within a team and you're all working on a product, then everybody in the team probably 32 33 00:02:43,170 --> 00:02:49,920 has both read and write permissions on a single remote repository. And that way, they can git clone and 33 34 00:02:49,920 --> 00:02:55,750 work on it locally, and then push it and resolve any sort of conflicts that way. 34 35 00:02:55,800 --> 00:03:00,080 But you don't want anybody on the internet having those kind of permissions. 35 36 00:03:00,090 --> 00:03:04,120 So how do you implement this kind of open source collaboration then? 36 37 00:03:04,140 --> 00:03:07,570 Well, it's through forking and making pull requests. 37 38 00:03:07,770 --> 00:03:12,990 So, now let's say that evil Angela, Bad-ngela has forked my repository. 38 39 00:03:13,140 --> 00:03:17,800 So on her GitHub account, she now owns a copy of my repository. 39 40 00:03:18,180 --> 00:03:24,340 And from this point, she can then clone that repository to work on it locally. 40 41 00:03:24,540 --> 00:03:31,680 And if she decides to add some features to it, maybe, you know, improve the codebase or add some more code, 41 42 00:03:31,800 --> 00:03:34,550 or do something crazy, or whatever it is that she wants, 42 43 00:03:34,690 --> 00:03:41,670 then after she's happy with that and she's committed those changes, then she can push it to her remote 43 44 00:03:41,670 --> 00:03:49,000 repository. And then if she wants me or good Angela to incorporate those changes that she made, then her 44 45 00:03:49,120 --> 00:03:56,130 only option is to make a pull request if she is not within that trusted pool of people who all have 45 46 00:03:56,130 --> 00:03:59,130 read and write access to my remote repository. 46 47 00:03:59,130 --> 00:04:05,490 So, say, if she only has read access, then she would have to make a pull request. And it's almost like making 47 48 00:04:05,520 --> 00:04:06,770 a suggestion. 48 49 00:04:06,900 --> 00:04:08,840 "Here are some suggested changes 49 50 00:04:08,850 --> 00:04:09,890 that I've been working on. 50 51 00:04:09,900 --> 00:04:16,430 What do you think about it? if you okay it, then please, you know, merge it to your remote repository." 51 52 00:04:16,740 --> 00:04:23,130 So the reason why it's called a pull request and not a push request is because the person who has the 52 53 00:04:23,130 --> 00:04:25,260 write permission to the repository, 53 54 00:04:25,290 --> 00:04:33,550 so I have write permission to my own remote repository which has been forked and duplicated by, you know, 54 55 00:04:33,930 --> 00:04:35,100 my evil twin. 55 56 00:04:35,100 --> 00:04:39,330 If she wants to incorporate those changes, then I have the deciding vote. 56 57 00:04:39,570 --> 00:04:45,270 So I can review those changes and I can pull the changes over. 57 58 00:04:45,420 --> 00:04:51,750 So it's not a push because you don't own the rights to the remote repository that you're trying to push 58 59 00:04:51,760 --> 00:04:53,070 to. 59 60 00:04:53,290 --> 00:04:59,740 In this case, if I decide after code review that, actually, those features actually added were pretty great, 60 61 00:04:59,740 --> 00:05:06,430 and it seems compatible with my code so far and doesn't break anything, then I would approve the pull 61 62 00:05:06,430 --> 00:05:12,190 request and merge her repository with my own. 62 63 00:05:12,370 --> 00:05:16,050 So the changes will be reflected in a new commit. 63 64 00:05:16,210 --> 00:05:18,330 So let's take a look at this in action. 64 65 00:05:20,060 --> 00:05:23,650 So here, we've got our original story repository. 65 66 00:05:23,690 --> 00:05:30,440 So this is a remote repository, remember, because it's hosted online on GitHub, and we've got a number 66 67 00:05:30,440 --> 00:05:37,840 of commits and we've been doing some modifications and writing to write our storyline. 67 68 00:05:37,850 --> 00:05:40,880 Now, I'm going to log out of my account. 68 69 00:05:41,060 --> 00:05:44,250 So that was the account that created the story. 69 70 00:05:44,540 --> 00:05:47,880 And then I'm going to sign in using a different account. 70 71 00:05:48,110 --> 00:05:52,220 So right now, I'm signed into a different GitHub account. 71 72 00:05:52,220 --> 00:05:55,720 This account is named gilfoyleismyothername. 72 73 00:05:55,790 --> 00:05:58,900 And now I'm going to search for that repository. 73 74 00:05:59,210 --> 00:06:03,250 So I found the story repository by the user angelabauer. 74 75 00:06:03,250 --> 00:06:05,700 So that was the one that we saw earlier on. 75 76 00:06:05,750 --> 00:06:11,960 So I'm going to go into this repository and you can see that all of these lines and files are publicly 76 77 00:06:11,960 --> 00:06:18,350 visible and you can read through all of it, even though you are now not signed in to the account that 77 78 00:06:18,350 --> 00:06:20,000 created this repository. 78 79 00:06:20,330 --> 00:06:25,760 So from here, what I'm going to do is I'm going to fork this repository. 79 80 00:06:26,360 --> 00:06:34,400 So as we mentioned before, forking is simply making a copy or a duplicate of a remote repository and 80 81 00:06:34,400 --> 00:06:40,970 putting it under your own GitHub account. So you can see this user that I've created is called 81 82 00:06:41,000 --> 00:06:42,550 gilfoyleismyothername. 82 83 00:06:42,620 --> 00:06:50,570 And now I have this repository under my own username, so I've made a copy of it, and you can see it's 83 84 00:06:50,570 --> 00:06:52,690 exactly the same as before. 84 85 00:06:52,760 --> 00:06:57,580 Everything's been copied over including all of the previous commits that were made. 85 86 00:06:57,620 --> 00:07:01,540 So, now from here, I'm going to-- 86 87 00:07:01,550 --> 00:07:03,840 So from here, I'm going to make some changes. 87 88 00:07:03,890 --> 00:07:11,870 So let's maybe change one of these storylines. So let's change chapter. 88 89 00:07:14,710 --> 00:07:22,120 So let's say that this other user, this other person, has some suggested improvements to my code. 89 90 00:07:22,120 --> 00:07:28,090 or in this case, to my writing. They're still keeping the spirit of the original repository alive because 90 91 00:07:28,090 --> 00:07:33,240 we are now converting into a space theme or an alien theme. 91 92 00:07:33,700 --> 00:07:41,470 So I've made my changes to chapter4 and I'm going to commit those changes saying, "Add more space themes 92 93 00:07:43,390 --> 00:07:45,500 to chapter 4." 93 94 00:07:45,550 --> 00:07:48,590 So that's what I did, and I'm going to commit to the mast a branch. 94 95 00:07:48,610 --> 00:07:54,780 This is the master branch of my own forked copy of the story repository. 95 96 00:07:54,850 --> 00:08:02,500 So once I commit those changes, then we can view what it currently looks like under the graphs. 96 97 00:08:02,530 --> 00:08:13,310 So if we have a look at the network, you can see that this is the point where I forked the story repository. 97 98 00:08:13,520 --> 00:08:14,390 That commit 98 99 00:08:14,420 --> 00:08:20,240 was created by Angela Yu which, basically, merged this branch to the master branch. 99 100 00:08:20,240 --> 00:08:23,500 So we did that two lessons back if you remember. 100 101 00:08:23,600 --> 00:08:29,360 So the latest commit though is made by this current user, gilfoyleismyothername. 101 102 00:08:29,480 --> 00:08:37,150 And you can see that I've added it to the master branch of my forked copy of that repository. 102 103 00:08:37,190 --> 00:08:47,090 So, say, if I now open up a Incognito window and I log back in to the Angela account, and go over to that 103 104 00:08:47,180 --> 00:08:55,900 story repository, you can see that if I have a look inside my graphs, go into Network, that that latest 104 105 00:08:55,910 --> 00:08:59,650 change, it's not reflected on my master branch. 105 106 00:08:59,660 --> 00:09:05,710 It's showing up as a separate branch made by gilfoyleismyothername. 106 107 00:09:05,840 --> 00:09:09,570 And you can see the members who have forked your repository. 107 108 00:09:09,950 --> 00:09:16,850 So this is a great way of collaborating because you can have contributors make edits or add new features 108 109 00:09:17,150 --> 00:09:21,620 to your preexisting codebase or repository. 109 110 00:09:22,000 --> 00:09:30,120 And now what I can do if I head back to the Gilfoyle account, so I'm just going to flip through these 110 111 00:09:30,120 --> 00:09:37,870 two so that you can see, right now I'm inside the Gilfoyle account and this is the Angela Bauer account. 111 112 00:09:38,220 --> 00:09:45,720 So, now under the Gilfoyle account, what I can do is I can make a pull request. So we can do that 112 113 00:09:45,720 --> 00:09:46,380 here. 113 114 00:09:46,770 --> 00:09:49,050 And you can see that it's able to merge. 114 115 00:09:49,530 --> 00:09:51,540 And these are the changes, 115 116 00:09:51,570 --> 00:09:55,620 so swapping that word for that word, swapping that word for that phrase. 116 117 00:09:55,680 --> 00:10:05,170 So, now all I have to do is hit create pull request and tell the original author, which is Angela Bauer, 117 118 00:10:05,640 --> 00:10:15,120 what I've done, why I think my modifications or my features are worthy to be merged with the original 118 119 00:10:15,120 --> 00:10:16,320 repository, 119 120 00:10:16,320 --> 00:10:17,760 and, you know, any other notes, 120 121 00:10:17,760 --> 00:10:18,000 right? 121 122 00:10:18,000 --> 00:10:20,590 Any other comments that I have. 122 123 00:10:20,730 --> 00:10:21,750 Let's just say-- 123 124 00:10:25,420 --> 00:10:26,890 Always helps to give complimentary. 124 125 00:10:26,890 --> 00:10:30,830 So, now let's go ahead and create a pull request. 125 126 00:10:33,560 --> 00:10:35,640 So the pull request is done. 126 127 00:10:35,700 --> 00:10:45,040 But if we have a look back into the story repository, you can see that those changes are not made, right? 127 128 00:10:45,060 --> 00:10:47,510 It's because I don't own this repository. 128 129 00:10:47,520 --> 00:10:49,050 I don't have write access. 129 130 00:10:49,050 --> 00:10:56,910 I only have read access as a member of the general public and not a member of the trusted inner circle. 130 131 00:10:57,240 --> 00:11:01,140 So I can only suggest my changes. 131 132 00:11:01,290 --> 00:11:07,530 Now, if we head over back to the Angela Bauer account, who owns this repository, 132 133 00:11:08,100 --> 00:11:14,360 now if I have a look under pull requests, I've got a brand-new pull request, right? 133 134 00:11:14,460 --> 00:11:15,820 So it previously was zero, 134 135 00:11:15,840 --> 00:11:23,900 but now I have one, and it's showing as one open pull request. And this is added a minute ago by Gilfoyle. 135 136 00:11:24,180 --> 00:11:32,300 And if I look at it, I can see why he thinks that this modification is necessary and what were his commit 136 137 00:11:32,340 --> 00:11:33,100 message, 137 138 00:11:33,360 --> 00:11:40,320 and I can also take a look at the commits that he made and compare the differences. 138 139 00:11:40,350 --> 00:11:42,780 So review those changes. 139 140 00:11:47,740 --> 00:11:49,440 So I could say something like, 140 141 00:11:49,450 --> 00:11:51,660 "Great job. 141 142 00:11:51,890 --> 00:11:53,100 "Great job, 142 143 00:11:54,290 --> 00:12:01,390 Gilfoyle." And I can submit this feedback to Gilfoyle and approve merging these changes. 143 144 00:12:03,800 --> 00:12:16,250 So, now all I have to do is hit merge pull request, and maybe add a "Merged from Gilfoyle's modifications 144 145 00:12:16,580 --> 00:12:18,930 to chapter 4." 145 146 00:12:19,340 --> 00:12:23,590 Okay, so let's go ahead and confirm the merge. 146 147 00:12:23,880 --> 00:12:30,010 And now you can see that that commit is added to Angela Bauer master. 147 148 00:12:30,030 --> 00:12:32,470 So if I have a look inside my graphs 148 149 00:12:32,470 --> 00:12:32,970 now, 149 150 00:12:35,760 --> 00:12:42,570 you can see that the latest commit was my merge and it was--and you can see where it came from. It came 150 151 00:12:42,570 --> 00:12:49,350 from a fork made by Gilfoyle which shows up as a separate branch, and then it got merged back into the 151 152 00:12:49,350 --> 00:12:52,080 main branch of the main repository. 152 153 00:12:52,110 --> 00:12:59,430 So some people use GitHub purely as version control for their own projects and use some of the features 153 154 00:12:59,430 --> 00:13:01,620 that we discussed in previous lessons. 154 155 00:13:01,890 --> 00:13:12,540 But there's also a huge community of awesome coders on here who have created really brilliant projects. 155 156 00:13:12,540 --> 00:13:19,860 And if you can see ways of improving it or contributing to it, then it's a great way of starting to 156 157 00:13:19,860 --> 00:13:26,250 learn how to work in a team of programmers which is a really essential skill when you're working for 157 158 00:13:26,250 --> 00:13:28,190 a startup or for a company. 158 159 00:13:28,740 --> 00:13:34,920 So for example, if we have a look at the Alamofire repository which is something that we've been using 159 160 00:13:34,920 --> 00:13:42,750 for quite a while, if you have a look at the contributions, you can see that there have been loads and 160 161 00:13:42,750 --> 00:13:49,890 loads of other users who have looked at the code and done things, you know, or made suggestions, and to 161 162 00:13:49,890 --> 00:13:55,530 steadily improve this framework that, you know, everybody else is benefiting off, 162 163 00:13:55,530 --> 00:13:56,140 right? 163 164 00:13:56,190 --> 00:14:02,760 You can see that a total of four4,300 forks have been made, and there's currently 4 164 165 00:14:02,820 --> 00:14:07,860 open pull requests, but 559 pull requests were closed. 165 166 00:14:07,920 --> 00:14:09,210 So let's have a look. 166 167 00:14:09,210 --> 00:14:16,030 So, for example, in this case, this guy updated the README to the current version, 167 168 00:14:16,050 --> 00:14:18,290 so that's obviously just editing a text file, 168 169 00:14:18,300 --> 00:14:21,720 and that's pretty much within anybody's capabilities, right? 169 170 00:14:21,930 --> 00:14:26,360 And then, it got merged by somebody who owned this repository. 170 171 00:14:26,650 --> 00:14:30,140 And you know they gave them a bit of feedback, right? 171 172 00:14:30,360 --> 00:14:36,960 But there's other things like, you know, code additions or code deletions, or modifications that people 172 173 00:14:36,960 --> 00:14:37,830 have made. 173 174 00:14:37,860 --> 00:14:46,590 So this guy made some fixes and, you know, he's documented what were the goals, what were the implementation 174 175 00:14:46,590 --> 00:14:47,360 details, 175 176 00:14:47,430 --> 00:14:49,530 what were the tests that he performed. 176 177 00:14:49,530 --> 00:14:55,360 And then the guy who owned the repository said, "Hey, just, you know, maybe one thing that you need to change, 177 178 00:14:55,440 --> 00:14:56,530 have a look in here." 178 179 00:14:56,580 --> 00:15:01,460 And then once it was changed, then it was approved and merged with the master branch. 179 180 00:15:01,710 --> 00:15:07,170 So have a look around on GitHub and see what are some of the cool projects that you could maybe get 180 181 00:15:07,170 --> 00:15:08,090 involved in. 181 182 00:15:08,310 --> 00:15:14,910 So to begin with, you know, some of these things that we've been using, for example, ProgressHUD, 182 183 00:15:14,910 --> 00:15:15,440 right? 183 184 00:15:15,450 --> 00:15:17,910 We've been using inside Quizzler. 184 185 00:15:18,000 --> 00:15:24,300 You can actually have a look inside the code files and see, you know, what are the things that you would 185 186 00:15:24,300 --> 00:15:25,560 change about it, 186 187 00:15:25,860 --> 00:15:32,880 obviously, ProgressHUD is written in Objective-C, maybe choose one that is written in Swift. But have 187 188 00:15:32,880 --> 00:15:34,830 a look at the libraries that you've been using, 188 189 00:15:34,830 --> 00:15:36,060 and if you want, 189 190 00:15:36,060 --> 00:15:42,840 you can build on top of it, either for your own goals and purposes. But also, you know, if you're building 190 191 00:15:42,840 --> 00:15:48,750 on top of somebody else's open source code, then it's a nice thing to contribute back to the open source 191 192 00:15:49,230 --> 00:15:57,950 world by forking and making a pull request to offer your improvements or bug fixes, or new features. 192 193 00:15:57,960 --> 00:16:07,620 So as I said, it's almost like a social network for programmers and you can make a lot of great friends 193 194 00:16:07,620 --> 00:16:14,370 on here, and you can also get a lot of help on here in your development journey. 194 195 00:16:14,370 --> 00:16:20,010 So the last thing that I wanted to say was that in this module, I've mentioned a lot of different 195 196 00:16:20,010 --> 00:16:26,250 GitHub or Git commands and it can be quite difficult to remember all of it just by watching these videos 196 197 00:16:26,250 --> 00:16:26,960 once. 197 198 00:16:27,000 --> 00:16:33,360 So remember, you always have these videos, so you can always come back and listen to my terrible 198 199 00:16:33,420 --> 00:16:34,060 jokes, 199 200 00:16:34,140 --> 00:16:37,400 but also the information again. 200 201 00:16:37,410 --> 00:16:40,630 So you can always rewatch it and refresh yourself. 201 202 00:16:41,100 --> 00:16:51,120 But I've actually made a PDF Cheat Sheet of some of the most common Git and GitHub commands that you'll 202 203 00:16:51,150 --> 00:16:52,470 be using. 203 204 00:16:52,470 --> 00:16:58,110 And I've laid it all out in terms of arrows that we've explained before so that you'll know what I'm 204 205 00:16:58,110 --> 00:17:03,010 talking about, and you can download this PDF inside this lesson. 205 206 00:17:03,240 --> 00:17:08,450 So I hope you enjoyed all of that and I will see you on the next lesson.