1 00:00:00,120 --> 00:00:07,050 So by forking, we've made a copy of the repository that exists on my account on Colt and I've made 2 00:00:07,050 --> 00:00:07,980 some changes locally. 3 00:00:07,980 --> 00:00:09,000 I push them up. 4 00:00:09,000 --> 00:00:09,930 We see the changes. 5 00:00:09,930 --> 00:00:13,800 We did this in the last video where it's that commit basic. 6 00:00:13,800 --> 00:00:14,390 No, not basic. 7 00:00:14,400 --> 00:00:17,400 Here it is change color palette on this style directory. 8 00:00:17,400 --> 00:00:24,180 Anyway, I have some work and it actually shows I am one commit ahead of the original repository that 9 00:00:24,180 --> 00:00:25,260 I forked from. 10 00:00:25,350 --> 00:00:31,350 So GitHub is actually telling me automatically, hey, you have some work on your fork that is not on 11 00:00:31,350 --> 00:00:37,830 the original and I can just ignore that and never do anything with the original, or I can actually 12 00:00:37,830 --> 00:00:41,130 share my work or attempt to share it by making a pull request. 13 00:00:41,130 --> 00:00:44,970 I can make a pull request from my fork to the original repository. 14 00:00:44,970 --> 00:00:50,310 So I'm not going to actually go through with it because I don't want to bother the creator of this repository 15 00:00:50,310 --> 00:00:53,580 with a dumb, useless pull request that they'll just close. 16 00:00:54,030 --> 00:00:56,130 But you can see it's the same interface. 17 00:00:56,130 --> 00:00:58,410 I can create a pull request with my changes. 18 00:00:58,410 --> 00:01:04,620 I can leave a comment, I can explain why you know why I think this should be merged in. 19 00:01:04,800 --> 00:01:10,260 And then the repository owner and anybody who has merge permissions can then take my poll request and 20 00:01:10,260 --> 00:01:12,600 merge it in or close it or whatever they want to do. 21 00:01:13,020 --> 00:01:15,840 So that mechanism is really, really important. 22 00:01:15,990 --> 00:01:21,060 This would be a way for me to make a real contribution, not the silly one that I did, but I could 23 00:01:21,060 --> 00:01:24,150 make a real contribution to a project that I don't own. 24 00:01:24,150 --> 00:01:27,720 I don't have permission to push to it, but I can fork it. 25 00:01:27,720 --> 00:01:31,980 I can make my own suggestions, my own changes, and then open up, pull request. 26 00:01:31,980 --> 00:01:34,080 And that's the basis of this workflow. 27 00:01:34,080 --> 00:01:36,630 So this workflow, I'm calling it fork and clone. 28 00:01:36,660 --> 00:01:38,250 Other people say fork and clone. 29 00:01:38,250 --> 00:01:41,040 I'm pretty sure it's not some official term, but it's common enough. 30 00:01:41,220 --> 00:01:47,160 It allows a whole bunch of people to work on the same project without actually all having permission 31 00:01:47,160 --> 00:01:50,040 and write permissions for the same repository. 32 00:01:50,220 --> 00:01:54,720 So I have some diagrams that I'll be using to illustrate how this all works. 33 00:01:55,290 --> 00:02:01,260 If we have three collaborators, which is just a subset, let's say we have way more on a big project, 34 00:02:01,260 --> 00:02:03,570 potentially thousands of people who want to collaborate. 35 00:02:03,570 --> 00:02:10,350 But here on the diagram, I've only included three people me somebody named Taylor and somebody named 36 00:02:10,350 --> 00:02:10,979 Lupe. 37 00:02:11,009 --> 00:02:14,550 And then we have the official project repository. 38 00:02:14,550 --> 00:02:21,330 Maybe we're working on React or some, I don't know, some big repository that we don't have access 39 00:02:21,330 --> 00:02:24,570 to, to directly push or change settings. 40 00:02:24,570 --> 00:02:26,130 We have to make a fork. 41 00:02:26,130 --> 00:02:29,340 So we each fork, that's what the fork is representing. 42 00:02:29,910 --> 00:02:33,990 And then on my local machine, I clone my fork. 43 00:02:33,990 --> 00:02:35,550 So that's what this is indicating. 44 00:02:35,820 --> 00:02:39,420 So I have my fork that I made from the original project repo. 45 00:02:39,450 --> 00:02:40,680 I cloned that down. 46 00:02:41,700 --> 00:02:45,390 So now I have this automatic remote set up called Origin. 47 00:02:45,390 --> 00:02:49,770 Just because I cloned this repository, the default remote name is going to be origin. 48 00:02:49,770 --> 00:02:52,380 So Origin refers to my fork. 49 00:02:52,680 --> 00:02:55,230 That's done automatically when I cloned. 50 00:02:55,620 --> 00:03:01,500 But then I'm going to set up a second remote and this remote is going to be anything I want. 51 00:03:01,500 --> 00:03:03,190 But normally we would call it upstream. 52 00:03:03,190 --> 00:03:07,710 That's a very conventional name and it refers to the original repo that we forked. 53 00:03:08,010 --> 00:03:14,010 So this allows me to basically have a place where I can do my own work and push changes up to. 54 00:03:14,010 --> 00:03:20,970 But also if there are changes made to the original repository on a large open source projects like React, 55 00:03:20,970 --> 00:03:24,300 there might be new commits and pull requests merge daily. 56 00:03:24,300 --> 00:03:26,910 I want to be able to get those down on my machine. 57 00:03:26,910 --> 00:03:33,870 So even if I can't push up, I can still pull changes down so often upstream or original will be the 58 00:03:33,870 --> 00:03:35,100 name of this remote. 59 00:03:35,460 --> 00:03:39,990 But now we have two remotes, one going to my fork and one going to the original. 60 00:03:40,080 --> 00:03:43,920 So now if I do some work, I make a new commit or a bunch of commits. 61 00:03:43,920 --> 00:03:48,360 Normally this would be on a feature branch, but for the diagram sake I'm just doing it on the main 62 00:03:48,360 --> 00:03:49,980 branch or whatever this branch is. 63 00:03:49,980 --> 00:03:52,920 So I make some work or I make some commits. 64 00:03:52,920 --> 00:03:59,460 Then if I want to try and share it with the repository creators, I definitely cannot push up because 65 00:03:59,460 --> 00:04:00,540 I don't have permission. 66 00:04:00,810 --> 00:04:05,190 So instead I can push up to my origin, which is my fork. 67 00:04:05,190 --> 00:04:06,720 I can push whatever I want up there. 68 00:04:06,720 --> 00:04:08,160 I could make the whole thing empty. 69 00:04:08,250 --> 00:04:11,700 I have permission to do anything with that because I own that fork. 70 00:04:11,700 --> 00:04:18,630 So now on GitHub I have my fork that I've worked on and I can make a pull request just like what I showed 71 00:04:18,630 --> 00:04:21,329 you here where I forked 2048. 72 00:04:21,329 --> 00:04:25,080 I can make a PR and ask for my changes to be merged in. 73 00:04:25,410 --> 00:04:31,110 So then if I do that, open up a pull request, then it's up to the original or the official project. 74 00:04:31,110 --> 00:04:37,770 Repo owners, somebody who maintains it, who has permission to accept, to merge or close my pull request. 75 00:04:38,220 --> 00:04:41,520 And if my pull request is accepted, it's merged in. 76 00:04:41,640 --> 00:04:48,540 So then the next step is basically show up at work again and pull down my changes from upstream. 77 00:04:48,540 --> 00:04:50,850 So there's new work that was done on upstream. 78 00:04:50,850 --> 00:04:55,200 I don't have it locally, so I go and get the latest from the real repository. 79 00:04:55,200 --> 00:04:58,740 I pull that down and then I can do some more work locally. 80 00:04:58,740 --> 00:04:59,970 Push that up to my. 81 00:05:00,270 --> 00:05:03,480 Fork and then from my fork make a request when necessary. 82 00:05:03,720 --> 00:05:09,120 So the whole point of this workflow is to allow people who don't have direct access, direct permission 83 00:05:09,120 --> 00:05:13,620 to push or to change anything in a project repository. 84 00:05:13,620 --> 00:05:18,840 They can still collaborate, they can still make pull requests by forking and then pushing their changes 85 00:05:18,840 --> 00:05:20,670 to their fork and opening a PR. 86 00:05:20,670 --> 00:05:25,710 So this would be the sort of cycle we pulled down the latest changes from the official repo. 87 00:05:25,740 --> 00:05:27,000 That's one remote. 88 00:05:27,030 --> 00:05:32,670 We make changes, we push them up to our fork and then we can make a pull request if we want, with 89 00:05:32,670 --> 00:05:36,510 suggestions or with our changes that we want to be merged into the original repo. 90 00:05:36,930 --> 00:05:39,690 And then we just wait and we hope that someone responds. 91 00:05:39,690 --> 00:05:42,420 So here's a short summary for the project. 92 00:05:42,420 --> 00:05:48,660 Clone the fork, add our upstream remote, do some work, push to the origin and then open a PR to the 93 00:05:48,660 --> 00:05:50,280 original or the upstream. 94 00:05:50,280 --> 00:05:55,260 So I'm going to demo that again in the next video we'll wrap up by just talking about why this is a 95 00:05:55,260 --> 00:05:55,920 good idea. 96 00:05:55,920 --> 00:06:01,770 In some situations, this is not a workflow that you may want to use on every single project that you're 97 00:06:01,770 --> 00:06:02,490 working on. 98 00:06:02,490 --> 00:06:09,000 But again, at a larger scale where there might be some project that thousands of people might be interested 99 00:06:09,000 --> 00:06:14,160 in working in, or even if it's just two or three people, but you don't want to give them access directly 100 00:06:14,390 --> 00:06:15,840 to your repository. 101 00:06:15,840 --> 00:06:21,600 People can still make these suggestions, they can make their own changes and hope that you merge them 102 00:06:21,600 --> 00:06:23,940 and they can make a pull request from their forks. 103 00:06:23,940 --> 00:06:29,550 So this allows us to work with tons and tons of people without having to have direct collaborators added 104 00:06:29,550 --> 00:06:30,270 to a repo.