1 00:00:00,090 --> 00:00:04,590 So now I'm going to demonstrate this fork and clone workflow on very, very simple terms. 2 00:00:04,590 --> 00:00:06,020 But the workflow is the same. 3 00:00:06,030 --> 00:00:08,250 We're just going to work on a very silly repository. 4 00:00:08,250 --> 00:00:15,870 So as Colt one GitHub user, I'm going to make a new repository and I'm not going to give anybody access. 5 00:00:16,200 --> 00:00:19,980 I'm going to make it public, of course, but I'm not going to make anybody a collaborator. 6 00:00:19,980 --> 00:00:22,020 So nobody will be able to push to this. 7 00:00:22,080 --> 00:00:25,770 I'll just call this fork and clone, maybe fork. 8 00:00:26,500 --> 00:00:28,300 Jase and clone. 9 00:00:29,050 --> 00:00:30,370 All right, it's public. 10 00:00:30,700 --> 00:00:35,080 I'll put a read me in there and then I'll create this repository. 11 00:00:37,960 --> 00:00:38,540 Okay. 12 00:00:38,770 --> 00:00:44,200 So now I'm going to just add, I have my initial commit, maybe I'll do one more commit. 13 00:00:44,200 --> 00:00:46,660 I'm just going to do it on GitHub to keep things simple. 14 00:00:46,960 --> 00:00:48,490 So this. 15 00:00:49,800 --> 00:00:56,550 Is a repo to demonstrate the fork and clone workflow. 16 00:00:57,710 --> 00:01:01,130 Sure we'll commit those changes to the main branch. 17 00:01:02,000 --> 00:01:03,320 And there we are. 18 00:01:04,550 --> 00:01:08,290 So the next thing that I'm going to do is change people. 19 00:01:08,300 --> 00:01:10,080 I'm going to switch over to Stevie. 20 00:01:10,100 --> 00:01:11,270 Pretend I'm Stevie. 21 00:01:11,300 --> 00:01:14,180 So here we are on Stevie's GitHub. 22 00:01:14,720 --> 00:01:16,130 I'm logged into Stevie here. 23 00:01:16,160 --> 00:01:17,180 Stevie checks. 24 00:01:17,180 --> 00:01:24,400 And if I go look at cults, repositories hate looking at this I can see forking clone. 25 00:01:25,370 --> 00:01:27,410 So this is the original project. 26 00:01:27,410 --> 00:01:29,870 I don't have access, I can't edit things. 27 00:01:29,870 --> 00:01:35,360 I mean, I can view it because it's public and I do want to collaborate, but say I want to, I don't 28 00:01:35,360 --> 00:01:40,280 know, I'll add some changes, I'll make a new file, whatever it is, there's some change that I want 29 00:01:40,280 --> 00:01:41,750 to work on and suggest. 30 00:01:41,750 --> 00:01:44,950 So I'm going to fork this repository as Stevie. 31 00:01:44,960 --> 00:01:51,410 So instead of Colt slash, fork and clone, hopefully we end up with Stevie Chick's slash fork and clone 32 00:01:51,440 --> 00:01:52,700 and it takes a moment. 33 00:01:52,700 --> 00:01:55,690 But when it's done forking, there we are. 34 00:01:55,700 --> 00:02:01,010 I now am going to copy this URL and clone this as Stevie. 35 00:02:01,400 --> 00:02:03,530 So over here, let me clean this up a bit. 36 00:02:03,920 --> 00:02:04,110 Okay. 37 00:02:04,250 --> 00:02:06,020 So I'm Stevie here. 38 00:02:06,020 --> 00:02:07,400 I'm going to back out. 39 00:02:07,580 --> 00:02:07,850 Sure. 40 00:02:07,850 --> 00:02:09,020 I'll just clone it right here. 41 00:02:09,020 --> 00:02:10,400 Make sure I'm not in a repo. 42 00:02:10,430 --> 00:02:12,530 Get clone that URL. 43 00:02:14,230 --> 00:02:15,130 Excellent. 44 00:02:15,550 --> 00:02:18,060 So now we have this fork in clone repository. 45 00:02:18,070 --> 00:02:19,660 Very simple single commit. 46 00:02:19,690 --> 00:02:22,810 No two commits in there from Colt Steel. 47 00:02:22,810 --> 00:02:24,520 And now I have cloned it. 48 00:02:24,520 --> 00:02:27,850 But if I look at my remote, I cloned the fork. 49 00:02:27,850 --> 00:02:32,080 So that remote is just pointing to my fork, not to the original. 50 00:02:32,560 --> 00:02:34,570 So I can push changes up. 51 00:02:34,570 --> 00:02:36,490 I can do that right now if I wanted to. 52 00:02:36,580 --> 00:02:39,640 But before that I'm going to just set up a second remote. 53 00:02:39,640 --> 00:02:44,830 And the reason for this, if I go back to my diagrams, is that I also want to be able to get changes 54 00:02:44,830 --> 00:02:48,310 that Colts might publish on the original project. 55 00:02:48,520 --> 00:02:51,220 Because my fork is frozen in time. 56 00:02:51,220 --> 00:02:53,860 I don't get changes from the original project. 57 00:02:53,860 --> 00:02:58,600 After I create the fork they are forking, they diverge, right? 58 00:02:59,110 --> 00:03:04,240 So if I want to stay up to date with what's happening and I want to get those changes on my repo from 59 00:03:04,240 --> 00:03:07,150 Colt's original, then I want to have a connection. 60 00:03:07,150 --> 00:03:12,880 I need a remote to refer to that original project repo so I'll just go to the original. 61 00:03:12,880 --> 00:03:14,740 So this is the original project. 62 00:03:14,740 --> 00:03:18,700 I'm going to copy this URL for Colt's version. 63 00:03:18,910 --> 00:03:19,570 All right. 64 00:03:19,570 --> 00:03:22,120 And then I'm going to add a remote. 65 00:03:22,120 --> 00:03:28,840 So it's git remote add, and then I'm going to call this one upstream because that's really common name 66 00:03:29,050 --> 00:03:35,440 or original or something to indicate this is the original thing I, I forked in clone. 67 00:03:35,470 --> 00:03:38,440 This is not my repository so I'll just go with upstream. 68 00:03:39,820 --> 00:03:43,150 So now if I do get remote V we have two remotes. 69 00:03:43,150 --> 00:03:46,300 I know it's kind of hard to see them here because they're not on one line. 70 00:03:47,460 --> 00:03:48,750 Let's make that full screen. 71 00:03:48,780 --> 00:03:49,350 Here we are. 72 00:03:49,380 --> 00:03:51,270 Origin goes to Stevie Nicks. 73 00:03:51,270 --> 00:03:53,610 Upstream goes to Colt's version. 74 00:03:53,840 --> 00:03:56,880 Okay, so now I'm switching back to Colt for a moment. 75 00:03:56,910 --> 00:04:03,210 Let's suppose that during all of this, this a couple of minutes while Stevie has been forcing and cloning, 76 00:04:03,810 --> 00:04:05,820 I'm working on this project as well. 77 00:04:05,820 --> 00:04:09,030 And again, I'm just going to do a very silly, simple change. 78 00:04:09,060 --> 00:04:11,910 I'm going to edit this, which we put in here for can. 79 00:04:14,850 --> 00:04:15,840 I. 80 00:04:15,930 --> 00:04:16,640 How about this? 81 00:04:16,649 --> 00:04:17,130 My. 82 00:04:17,839 --> 00:04:21,300 My favorite ice cream flavors. 83 00:04:22,170 --> 00:04:24,660 And then we'll do in no particular order. 84 00:04:26,160 --> 00:04:26,850 Mint. 85 00:04:27,480 --> 00:04:29,310 Well, my actual favorite is peppermint. 86 00:04:31,300 --> 00:04:32,260 That's not that common. 87 00:04:32,260 --> 00:04:36,160 And then I'll say mint chip, and then let's just leave it at that for now. 88 00:04:36,430 --> 00:04:38,470 All right, so there's my new commit. 89 00:04:38,620 --> 00:04:42,130 I'll go with add ice cream to read me. 90 00:04:42,430 --> 00:04:43,900 Commit changes to Main. 91 00:04:44,580 --> 00:04:48,150 So this is happening on Colt's original repository. 92 00:04:48,330 --> 00:04:49,950 Stevie's Falk doesn't have that. 93 00:04:49,950 --> 00:04:51,000 They diverged. 94 00:04:51,000 --> 00:04:52,980 They're not in sync anymore. 95 00:04:53,010 --> 00:04:57,300 This is a fork from a moment in time, so they're not attached. 96 00:04:57,450 --> 00:05:03,990 However, I can still get those changes because locally I have those two remotes. 97 00:05:03,990 --> 00:05:07,710 So if I want the latest, it's just make sure it gets status. 98 00:05:08,220 --> 00:05:13,980 Everything's up to date with origin, but if I want the latest from Colt's repository, I can do a get 99 00:05:13,980 --> 00:05:20,910 poll and then the remote is upstream and then whatever branch I'm looking for, I want main so I'll 100 00:05:20,910 --> 00:05:28,590 pull down from upstream and if I do a quick git log we see we have ice cream now add ice cream to read 101 00:05:28,590 --> 00:05:29,040 me. 102 00:05:29,400 --> 00:05:36,000 So now I could make some more changes on this potentially like let's say, what would I want to do if 103 00:05:36,000 --> 00:05:39,690 I just open it over here in my text editor here's the read me file. 104 00:05:40,170 --> 00:05:44,370 Let's do something like Steve's favorite. 105 00:05:47,130 --> 00:05:48,900 Ice cream flavors. 106 00:05:48,900 --> 00:05:50,520 And then Stevie is a chicken. 107 00:05:50,520 --> 00:05:59,400 So Stevie really likes mealworms, maybe like shrimp flakes and sunflower seeds. 108 00:06:01,770 --> 00:06:09,990 Och so we make a change, we'll add that commit so get add read me I'm doing this all as Stevie blocking 109 00:06:09,990 --> 00:06:16,620 that but I'm all I'm working at Stevie the chicken right now so get commit let's do something like add 110 00:06:16,980 --> 00:06:27,270 Stevie's Stevie fave ice cream not a great message but trying to keep this quick so if I want to make 111 00:06:27,270 --> 00:06:34,110 a suggestion to the original project that they include this this new commit that I've made or whatever 112 00:06:34,110 --> 00:06:35,220 multiple commits. 113 00:06:35,220 --> 00:06:40,200 First of all, normally we'd be working on a branch and we are in a branch, but we'd work on a separate 114 00:06:40,200 --> 00:06:43,200 branch, a feature branch, just to keep it simple. 115 00:06:43,200 --> 00:06:49,380 I'm just working on Main as well, so I don't have permission to push this up to upstream, but I do 116 00:06:49,380 --> 00:06:52,020 have permission to push to my fork. 117 00:06:52,020 --> 00:06:53,310 So that's what I'm going to do. 118 00:06:53,340 --> 00:06:59,700 Remember that my fork I labeled well, I didn't label, but the default name for that remote is origin. 119 00:07:00,630 --> 00:07:02,590 Make that full screen as Stevie. 120 00:07:02,610 --> 00:07:04,290 This is what I can push to. 121 00:07:04,320 --> 00:07:05,910 I'm not allowed to push to this. 122 00:07:05,910 --> 00:07:06,720 I don't own it. 123 00:07:06,720 --> 00:07:08,700 I don't have collaborator privileges. 124 00:07:08,700 --> 00:07:13,380 So I'm going to push up to Origin, get push, and then we'll do Origin. 125 00:07:13,800 --> 00:07:16,770 And then Main is just the branch we're working on. 126 00:07:17,930 --> 00:07:25,010 And when that finishes, I should be able to refresh on my fork as Stevie checks and we see Stevie's 127 00:07:25,010 --> 00:07:28,820 flavors are down there but at the original does not have it. 128 00:07:28,820 --> 00:07:34,040 So you can see I am one commit ahead of Colt's version if we just open that in a tab. 129 00:07:34,250 --> 00:07:36,620 This is what Colts original version looks like. 130 00:07:36,620 --> 00:07:41,840 So we we now have this work that we could suggest, and that's exactly what I'm going to do. 131 00:07:41,840 --> 00:07:43,490 I'm going to open a pull request. 132 00:07:43,490 --> 00:07:45,350 That's the next step in this diagram. 133 00:07:45,650 --> 00:07:51,260 Should we make our changes, we push them up to our fork and then I pull request I make a pull request 134 00:07:51,260 --> 00:07:52,940 to the original project. 135 00:07:52,940 --> 00:07:56,540 So as Stevie, I'm going to make that pull request. 136 00:07:58,770 --> 00:08:00,780 Thankfully, it's a very easy one to merge. 137 00:08:00,780 --> 00:08:01,960 I'm going to ask. 138 00:08:01,980 --> 00:08:04,590 Please, please allow this in. 139 00:08:06,150 --> 00:08:07,050 Please. 140 00:08:07,800 --> 00:08:09,780 I'm just a little chicken. 141 00:08:11,160 --> 00:08:14,100 I want to make this PR. 142 00:08:15,110 --> 00:08:15,440 Bock. 143 00:08:15,440 --> 00:08:16,160 Bock. 144 00:08:16,580 --> 00:08:17,360 All right. 145 00:08:17,360 --> 00:08:20,810 So then I'm going to create, pull, request. 146 00:08:21,500 --> 00:08:24,230 Take a look here specifically. 147 00:08:24,230 --> 00:08:26,180 I'm going from main to main. 148 00:08:26,180 --> 00:08:27,580 That's not that common. 149 00:08:27,590 --> 00:08:29,840 Normally we'd be working on a feature branch. 150 00:08:29,840 --> 00:08:34,400 We saw how to make a pull request from a feature branch in the last what a couple of videos ago. 151 00:08:34,400 --> 00:08:35,480 So it's the same process. 152 00:08:35,480 --> 00:08:36,620 You just change the branch. 153 00:08:36,620 --> 00:08:38,990 We just don't have a different branch to pick from right now. 154 00:08:39,049 --> 00:08:44,570 So from my fork to the original main to main, here's my comment, please. 155 00:08:44,570 --> 00:08:46,010 Here's my pull request. 156 00:08:46,910 --> 00:08:49,700 All right, so I can't merge that in. 157 00:08:49,700 --> 00:08:50,660 I don't have access. 158 00:08:50,660 --> 00:08:55,370 I'm not the decider, but I just wait here and I hope that I hear back maybe some feedback. 159 00:08:55,370 --> 00:08:57,800 I hope it's not just closed, but it may be. 160 00:08:58,220 --> 00:09:04,190 Now as Colts, I'll go to pull requests, I'll refresh and we should see a new poll request. 161 00:09:05,560 --> 00:09:06,730 And here it is. 162 00:09:06,730 --> 00:09:11,350 I am the only person in charge I get to review and decide if I want to merge this in or not. 163 00:09:11,350 --> 00:09:15,250 And let's say that I'm happy with it, so I will merge it in. 164 00:09:16,000 --> 00:09:16,960 Confirm. 165 00:09:18,860 --> 00:09:25,100 Now I have successfully merged in that poll request, so that means that fork and clone on my account. 166 00:09:25,100 --> 00:09:28,550 Colt now has the new information from Steve's. 167 00:09:28,550 --> 00:09:32,540 And so now we have completed this cycle at least one time. 168 00:09:32,990 --> 00:09:38,450 So Steve made some changes, push them to the fork, made a pull request, the pull request was accepted 169 00:09:38,450 --> 00:09:39,710 and merged in. 170 00:09:39,710 --> 00:09:44,260 And so now this original repository has Steve's changes. 171 00:09:44,270 --> 00:09:48,800 So this process is all over the place with open source development. 172 00:09:49,040 --> 00:09:54,470 If we just take a look at any big git repository, let's take a look at here's react. 173 00:09:54,710 --> 00:09:59,330 We can see lots and lots of contributors, I mean, used by millions of people. 174 00:09:59,780 --> 00:10:01,430 And if I go to pull requests. 175 00:10:02,610 --> 00:10:04,030 I showed this a while ago. 176 00:10:04,050 --> 00:10:05,790 Lots and lots of pull requests. 177 00:10:05,790 --> 00:10:11,760 And if we look at where the pull requests are originating from, let's just pick any of them. 178 00:10:12,900 --> 00:10:13,670 It doesn't really matter. 179 00:10:13,680 --> 00:10:13,920 Sure. 180 00:10:13,920 --> 00:10:14,610 This one. 181 00:10:16,810 --> 00:10:24,750 Notice that it says this person already pennacchio wants to merge one commit into Facebook master branch 182 00:10:24,760 --> 00:10:29,140 from Ari's particular fork and then a feature branch. 183 00:10:29,140 --> 00:10:30,820 So notice the prefix, right? 184 00:10:30,820 --> 00:10:33,820 Facebook master versus Ari per. 185 00:10:34,250 --> 00:10:36,940 Sorry if you're watching this, Ari, you're probably not watching this. 186 00:10:36,940 --> 00:10:39,400 But anyway, that's a fork. 187 00:10:39,550 --> 00:10:42,760 So this is a fork that was made and we can go take a look. 188 00:10:42,760 --> 00:10:43,990 Here is that fork. 189 00:10:44,500 --> 00:10:47,380 This is Ari's fork of the original React. 190 00:10:47,380 --> 00:10:50,510 And they made a pull request and now they're just waiting their. 191 00:10:50,590 --> 00:10:51,850 Yeah, well, they're not even just waiting. 192 00:10:51,850 --> 00:10:56,410 There's a conversation happening about this poll request, but it's still open. 193 00:10:56,620 --> 00:11:02,080 So that's the basic workflow and that's how all of these contributors are making their contributions. 194 00:11:02,080 --> 00:11:08,020 They're forking and then making a pull request over with their changes and then to stay up to date with 195 00:11:08,020 --> 00:11:11,230 what actually changes on the official repository. 196 00:11:11,320 --> 00:11:17,440 Remember this step pulling down to get the latest changes from the official project repo so that you're 197 00:11:17,440 --> 00:11:19,870 up to date with the work everyone else has merged in.