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