1 00:00:00,060 --> 00:00:05,610 So in this video I'm going to demonstrate this merging workflow we've already seen, and then we'll 2 00:00:05,610 --> 00:00:09,690 set things up so that we can then rebase and see a difference. 3 00:00:10,050 --> 00:00:14,730 Otherwise, if I just show you rebasing on its own, it's a little bit harder to see how it compares. 4 00:00:14,910 --> 00:00:15,600 All right. 5 00:00:15,720 --> 00:00:20,140 So I'm going to make a new I already made a folder called Rebase Demo. 6 00:00:20,160 --> 00:00:25,470 I'm going to keep this extremely simple in terms of what my commits are in the history I create. 7 00:00:26,190 --> 00:00:32,729 Currently no git repo, so I'm going to init and I'll just work on the default master branch for now. 8 00:00:33,030 --> 00:00:40,170 And let's say that we're working on some project called I don't know, website. 9 00:00:40,440 --> 00:00:43,410 Website is going to be a text file just to keep things simple. 10 00:00:43,440 --> 00:00:45,210 All right, so I'll add that file. 11 00:00:45,660 --> 00:00:46,620 I will commit. 12 00:00:46,620 --> 00:00:50,130 Just initial commit, just like that. 13 00:00:50,130 --> 00:00:51,120 Nice and simple. 14 00:00:51,330 --> 00:00:54,140 All right, so we have our our website file open. 15 00:00:54,150 --> 00:00:55,410 I'm not going to be typing code. 16 00:00:55,410 --> 00:01:00,240 I'm just going to pretend we'll do something like nav bar added. 17 00:01:00,660 --> 00:01:03,650 That's the equivalent of somebody actually adding a nav bar in. 18 00:01:03,660 --> 00:01:04,290 All right. 19 00:01:04,290 --> 00:01:09,330 So now I'm going to commit that just just dash am nav bar. 20 00:01:09,630 --> 00:01:11,280 How about add nav bar? 21 00:01:12,480 --> 00:01:14,970 So now I'm going to switch over to a feature branch. 22 00:01:14,970 --> 00:01:17,220 We'll imagine that I'm working on this feature branch. 23 00:01:17,850 --> 00:01:22,620 Whatever the feature is, I'm just going to call it FT, just like that effort. 24 00:01:22,650 --> 00:01:28,380 So I'm on this branch, I'm going to be working in a separate file just to minimise conflicts. 25 00:01:28,560 --> 00:01:31,650 I'll also talk about what happens if we do have conflicts when we rebase. 26 00:01:31,650 --> 00:01:34,140 Anyway, what should my file be? 27 00:01:34,140 --> 00:01:37,590 Let's just call it feature text. 28 00:01:37,890 --> 00:01:38,370 All right. 29 00:01:38,370 --> 00:01:40,290 So I'm going to make this incredibly basic. 30 00:01:40,290 --> 00:01:50,160 As I said, I'm going to add feature just to start, get, commit, dash and begin feature, begin, 31 00:01:50,190 --> 00:01:52,020 begin feature. 32 00:01:53,730 --> 00:01:57,090 And then I'll do one other change in the feature. 33 00:01:57,540 --> 00:02:01,260 I think my changes in here are just going to be numbers, right? 34 00:02:01,260 --> 00:02:08,070 So one and then I'll go back get commit dash am work on feature. 35 00:02:09,220 --> 00:02:09,850 Okay. 36 00:02:09,880 --> 00:02:12,010 So I'm not going to switch back to Master. 37 00:02:12,040 --> 00:02:13,390 Get switch, master. 38 00:02:14,340 --> 00:02:16,680 There's no feature file and no feature branch. 39 00:02:16,830 --> 00:02:17,760 We're on, master. 40 00:02:18,180 --> 00:02:20,860 Let's say that somebody adds the footer. 41 00:02:20,880 --> 00:02:24,440 So this is new work someone has done in the meantime, right? 42 00:02:24,450 --> 00:02:25,890 So I'm working on my feature branch. 43 00:02:25,890 --> 00:02:26,880 I have some commits. 44 00:02:27,120 --> 00:02:30,870 Then changes are merged into master that I don't have on feature. 45 00:02:30,870 --> 00:02:32,400 So that's what I'm doing right now. 46 00:02:32,400 --> 00:02:41,220 The footer was added, so I will do a get commit dash a m footer, add footer. 47 00:02:43,350 --> 00:02:46,080 So here's what things look like and get cracking currently. 48 00:02:46,380 --> 00:02:50,030 So we have our master branch and then we have the feature branch. 49 00:02:50,040 --> 00:02:54,000 If I want to keep working on my feature branch, but I want the latest work from Master. 50 00:02:54,030 --> 00:02:56,100 We'll pretend it's coming from somebody else. 51 00:02:56,100 --> 00:02:56,580 Did this work? 52 00:02:56,580 --> 00:02:57,480 Not just me. 53 00:02:57,960 --> 00:02:59,640 I want that on my feature branch. 54 00:02:59,640 --> 00:03:04,410 I could do a merge on feature, so merge master into feature. 55 00:03:04,410 --> 00:03:06,210 And that's what I'm going to begin with. 56 00:03:06,450 --> 00:03:10,530 Exactly what I did here where we end up with a merge commit on feature. 57 00:03:10,530 --> 00:03:11,910 So I'm going to do that. 58 00:03:12,030 --> 00:03:14,340 So I'm on master right now. 59 00:03:14,490 --> 00:03:14,910 Right. 60 00:03:14,910 --> 00:03:17,130 I'm just going to take a look at my log. 61 00:03:17,940 --> 00:03:22,980 We have three commits on master, but if I switch back to feat. 62 00:03:25,030 --> 00:03:27,490 I want to merge in the changes from master. 63 00:03:27,490 --> 00:03:29,560 So get merge master. 64 00:03:29,570 --> 00:03:31,270 I'm on the feature branch. 65 00:03:31,570 --> 00:03:34,210 So again, see what it looks like right now. 66 00:03:34,210 --> 00:03:34,480 Right. 67 00:03:34,540 --> 00:03:35,200 I've diverged. 68 00:03:35,200 --> 00:03:36,310 There's new work on Master. 69 00:03:36,310 --> 00:03:38,080 I want that on my feature branch. 70 00:03:38,080 --> 00:03:41,500 I'm not done with the feature, but I want the latest work from Master. 71 00:03:42,610 --> 00:03:47,530 So it prompts me and my editor here, or if you don't have your editor configured, it'll prompt you 72 00:03:47,560 --> 00:03:50,290 here and your terminal with whatever your default editor is. 73 00:03:51,160 --> 00:03:53,170 I'm going to just close this. 74 00:03:53,200 --> 00:03:54,430 It's just a merge commit. 75 00:03:54,820 --> 00:03:57,070 So now we have this merge commit. 76 00:03:57,070 --> 00:03:57,610 Right. 77 00:03:58,310 --> 00:03:59,040 Right there. 78 00:03:59,050 --> 00:04:00,940 Merge branch master into ft. 79 00:04:01,540 --> 00:04:02,890 You can see what it looks like here. 80 00:04:02,890 --> 00:04:04,750 We have this merge commit right there. 81 00:04:05,420 --> 00:04:06,050 Okay. 82 00:04:06,070 --> 00:04:06,880 And it's not too bad. 83 00:04:06,880 --> 00:04:07,810 I guess so. 84 00:04:07,810 --> 00:04:09,260 I keep working on my feature. 85 00:04:09,280 --> 00:04:16,029 Let's say I get to two, whatever two is that is more work on my feature. 86 00:04:16,029 --> 00:04:18,130 So I'm trying to just keep this super simple. 87 00:04:18,610 --> 00:04:19,240 All right. 88 00:04:19,510 --> 00:04:20,529 Work more. 89 00:04:20,529 --> 00:04:21,610 Work on feature. 90 00:04:23,880 --> 00:04:24,320 Okay. 91 00:04:24,330 --> 00:04:27,660 And then in the meantime, let's say that took me like half a day. 92 00:04:27,690 --> 00:04:31,590 Go back to Master and we'll pretend we're other people on Master. 93 00:04:31,620 --> 00:04:37,050 A coworker finished some feature they're working on login form added. 94 00:04:37,910 --> 00:04:38,510 Right. 95 00:04:38,910 --> 00:04:48,150 So I will add that just to pretend I'm one of them or I'll just do a commit a form, add login form. 96 00:04:51,260 --> 00:04:53,360 And the feature I'm working on. 97 00:04:53,390 --> 00:04:58,370 Actually, it would be really useful if I had that login form on that feature branch. 98 00:04:58,370 --> 00:05:00,920 So once again I could do the same thing. 99 00:05:01,220 --> 00:05:06,950 I could go onto the feature branch and merge master into feature. 100 00:05:07,800 --> 00:05:11,660 So I'm going to do that because now there's a commit that I don't have. 101 00:05:11,670 --> 00:05:18,990 So I go back to feature, get switch and then I'm going to do a just get status, make sure I don't 102 00:05:18,990 --> 00:05:21,870 have any uncommitted stuff, get merge master. 103 00:05:22,440 --> 00:05:24,030 So here's what it looks like now. 104 00:05:24,690 --> 00:05:27,870 Here's my comment on feature that does not exist on Master. 105 00:05:27,900 --> 00:05:29,310 Here's the commit on Master. 106 00:05:29,310 --> 00:05:31,340 The new work, the login form. 107 00:05:31,350 --> 00:05:34,020 I want to merge that in to my feature branch. 108 00:05:34,020 --> 00:05:35,130 So I'm still not touching. 109 00:05:35,130 --> 00:05:36,540 I'm not changing master. 110 00:05:36,540 --> 00:05:42,480 Well, I am for this demo, but my feature branch is not merged into master at any point. 111 00:05:42,480 --> 00:05:44,340 I'm still just working on feature. 112 00:05:44,640 --> 00:05:47,670 So once again it generates a new merge commit. 113 00:05:47,670 --> 00:05:50,010 And now my history here. 114 00:05:50,340 --> 00:05:52,710 It doesn't look super bad because it's small. 115 00:05:52,710 --> 00:05:57,420 There's not a lot of merge commits, but there's another merge commit on my feature branch and if I 116 00:05:57,420 --> 00:06:00,060 look at my history I get log. 117 00:06:02,010 --> 00:06:02,330 Right. 118 00:06:02,330 --> 00:06:06,160 I have all this work, but then I have Merge Branch and then some more. 119 00:06:06,170 --> 00:06:09,470 Some more work, some more work and then merge branch again. 120 00:06:09,470 --> 00:06:15,470 So the history of my, my one feature branch that I'm working on is already cluttered and I just have 121 00:06:15,470 --> 00:06:16,250 to merge commits. 122 00:06:16,250 --> 00:06:22,460 But as I do more work on this one feature and as the master branch continues to change and there are 123 00:06:22,460 --> 00:06:27,320 more and more commits added on to it, I end up with a lot of merge commits if I want to stay up to 124 00:06:27,320 --> 00:06:30,680 date, if I want my feature branch to have the latest work from Master. 125 00:06:31,280 --> 00:06:37,520 So we end up with this sort of scenario where my feature branch constantly has merge commits, the history 126 00:06:37,520 --> 00:06:41,600 is cluttered, it's muddied, it's uglier, it's harder to follow. 127 00:06:41,600 --> 00:06:43,230 Now, this isn't a huge deal, right? 128 00:06:43,250 --> 00:06:44,840 It's not the end of the world. 129 00:06:44,840 --> 00:06:50,210 But on a really large project with lots and lots of commits, it can be way nicer if you have a clean 130 00:06:50,210 --> 00:06:56,420 commit history or a clean project history where the commits are grouped together in a logical way and 131 00:06:56,420 --> 00:06:59,030 you minimize the number of those merge commits. 132 00:06:59,030 --> 00:07:01,340 So that is what rebasing helps us do. 133 00:07:01,340 --> 00:07:07,310 In the next video, I'll actually use the commands that we talked about briefly to show you how to rebase 134 00:07:07,460 --> 00:07:12,830 so that we don't end up with these merge commits, but instead we end up with this nice linear history 135 00:07:12,830 --> 00:07:14,000 by rewriting it. 136 00:07:14,000 --> 00:07:14,750 So that's coming up.