1 00:00:00,710 --> 00:00:01,480 Welcome back. 2 00:00:01,670 --> 00:00:09,430 Let's continue from our previous video to talk about a more advanced workflow and git and github. 3 00:00:10,700 --> 00:00:16,490 Now up to this point both Marcy and I have just been working on over here. 4 00:00:16,490 --> 00:00:19,110 Branch master what does that mean. 5 00:00:19,280 --> 00:00:27,240 Well it says branches but I only see master here and you might have noticed one issue with the way that 6 00:00:27,240 --> 00:00:28,520 we were doing things. 7 00:00:28,710 --> 00:00:34,030 That is if it's my first day on the job and I just changed the title. 8 00:00:34,320 --> 00:00:36,030 But maybe we didn't even want that change. 9 00:00:36,030 --> 00:00:40,650 Maybe that breaks our branding or breaks our app. 10 00:00:40,650 --> 00:00:44,350 But I was able to do it so easily to change it into Master. 11 00:00:44,400 --> 00:00:48,840 Maybe Marcy didn't even know that I've added that change and that's a big problem right. 12 00:00:48,840 --> 00:00:53,830 You don't want to put things into what we call production into what the user sees. 13 00:00:54,360 --> 00:00:59,820 If it's going to break our website if you're a big company like Facebook that could mean millions of 14 00:00:59,820 --> 00:01:07,030 dollars in lost revenue even if you have a bug that lasts a few hours so I'm going to show you a more 15 00:01:07,030 --> 00:01:09,360 realistic workflow that you'll have. 16 00:01:09,370 --> 00:01:12,860 And that is with branching. Let me show you what I mean. 17 00:01:14,300 --> 00:01:18,760 I have over here a visual of what git is really really good at. 18 00:01:18,890 --> 00:01:22,410 Up until now we've been working on what we call master. 19 00:01:22,580 --> 00:01:24,250 That is the master branch. 20 00:01:24,250 --> 00:01:28,270 Think of the master branch as the authority. 21 00:01:28,310 --> 00:01:33,000 This is the right way that our app or our Web site should look. 22 00:01:33,010 --> 00:01:41,660 And up until now when I added the cool background title Well I went from a background generator to 23 00:01:42,530 --> 00:01:47,600 cool generator and then when Marcy changed to capitalized letters. 24 00:01:47,600 --> 00:01:52,820 Then we went to here and we just went in a linear fashion from one end to the other to the other to 25 00:01:52,820 --> 00:01:53,650 the other. 26 00:01:54,030 --> 00:01:56,490 But like I said that is a bit of a problem. 27 00:01:56,510 --> 00:01:59,900 So a better thing to do is what we call branching. 28 00:01:59,900 --> 00:02:06,420 If I wanted to change the title I will create a branch and just call that little feature for example. 29 00:02:06,890 --> 00:02:15,290 And I just work on that branch on my own without affecting the master branch what the user sees. 30 00:02:15,540 --> 00:02:20,950 Only when it's finished when Marcy has reviewed it when we have tested it and everybody on the team 31 00:02:20,950 --> 00:02:21,780 is OK. 32 00:02:21,950 --> 00:02:29,140 Then we bring it back into master and you can see over here with the big feature you can keep going for 33 00:02:29,140 --> 00:02:38,140 a long time on your own branch and only when you're done do what we call merge into Master. 34 00:02:38,200 --> 00:02:39,710 I'm going to show you how that works today. 35 00:02:41,360 --> 00:02:42,280 I'm gonna close this. 36 00:02:42,290 --> 00:02:51,440 And remember our example we have Marcy's computer here with all the files and we have my computer here 37 00:02:51,530 --> 00:02:52,750 with all the files. 38 00:02:53,030 --> 00:03:00,560 We both have our workstations set up and now you see what master in my terminal means and I'll show 39 00:03:00,560 --> 00:03:05,880 you in the notes afterwards how you can have this set up so it tells you what branch you're on. 40 00:03:05,900 --> 00:03:12,770 But we can see that we're both on Master. That's my computer and Marcy's computer is also in Master. 41 00:03:12,950 --> 00:03:18,470 We want to make sure that we're both up to date with the latest github. 42 00:03:18,470 --> 00:03:22,950 So Marcy's going to do git pull and I'm also going to do git pull. 43 00:03:26,460 --> 00:03:33,090 And let's say that I'm now working on a new feature and because it's a better workflow not to work on 44 00:03:33,090 --> 00:03:33,590 master. 45 00:03:33,600 --> 00:03:37,730 And this is a good tip generally don't work on master, always branch off. 46 00:03:37,860 --> 00:03:44,790 If I do git branch they'll show me that well I only have one branch and that is master but we can add 47 00:03:44,790 --> 00:03:57,340 to it we can say git branch new or little feature and now if I do git branch I see that I have little 48 00:03:57,340 --> 00:04:00,970 feature but Master is highlighted because I'm currently on master. 49 00:04:01,210 --> 00:04:11,160 So the way I would go to the little feature branch I'll say git checkout little feature and there you 50 00:04:11,160 --> 00:04:11,390 go. 51 00:04:11,400 --> 00:04:13,140 Switch to branch little feature. 52 00:04:13,140 --> 00:04:21,480 And now I'm on a little feature branch so what I've done is I've branched off of master and now created 53 00:04:22,079 --> 00:04:24,890 little feature. 54 00:04:25,100 --> 00:04:26,830 Let's create a bit of a change. 55 00:04:26,840 --> 00:04:33,770 I'm going to say in the little feature we're going to change the current CSS background title to say 56 00:04:34,850 --> 00:04:36,890 this is the background 57 00:04:41,010 --> 00:04:42,080 I'm going to save here. 58 00:04:42,360 --> 00:04:49,100 And again I do my simple workflow that we did in the last video git status. 59 00:04:49,170 --> 00:04:49,680 I see that. 60 00:04:49,680 --> 00:04:49,990 Yeah. 61 00:04:50,130 --> 00:04:53,630 We have the index.html changed, going to clear so we can see. 62 00:04:53,650 --> 00:05:02,720 So now that we've made this change let's do git add and again just git status to make sure everything 63 00:05:02,720 --> 00:05:03,330 went through. 64 00:05:03,470 --> 00:05:06,090 Yeah we're ready to commit index.html. 65 00:05:06,110 --> 00:05:14,310 So we'll git commit message will be changing text. Perfect. 66 00:05:14,330 --> 00:05:16,020 Let's clear that. 67 00:05:16,210 --> 00:05:21,880 And now again in order to let github know all of the changes we need to do git push. 68 00:05:22,160 --> 00:05:23,900 So we'll do git push. 69 00:05:29,960 --> 00:05:32,930 Lets go to github and see what happened. 70 00:05:34,950 --> 00:05:40,650 We see that now we have this yellow bar that just showed up and says "You recently pushed branches". 71 00:05:41,760 --> 00:05:44,550 So if I click on this green button here compare and pull request 72 00:05:47,790 --> 00:05:54,640 it shows me what changes I have which is I've changed the title and here I can let Marcy know saying 73 00:05:54,650 --> 00:05:59,330 "Marcy I've changed the text." 74 00:05:59,800 --> 00:06:03,450 "What do you think". And I click on Create pull request 75 00:06:06,480 --> 00:06:11,410 and now I have my PR and you see here how it says merge pull request. 76 00:06:11,430 --> 00:06:18,570 Well if we go back to our diagram I've created this little feature and now I'm saying hey Marcy I've 77 00:06:18,690 --> 00:06:20,820 just done this new change. 78 00:06:20,820 --> 00:06:21,750 What do you think. 79 00:06:21,780 --> 00:06:25,200 Is it OK for me to merge it into master. 80 00:06:25,380 --> 00:06:31,230 And what will happen here most likely as Marcy's will come see this pull request. 81 00:06:31,230 --> 00:06:33,180 You can see that we're on the pull request tabs. 82 00:06:33,210 --> 00:06:37,420 So she'll be able to see them and seeing Oh Andrea just did this change. 83 00:06:37,620 --> 00:06:46,860 She'll look through the changes and she'll say Hmm well if she like says she can be like looks good 84 00:06:47,910 --> 00:06:53,240 she can click on start a review and you know what she really likes it so she's just going to approve 85 00:07:01,310 --> 00:07:04,040 Now Marcy or myself. 86 00:07:04,040 --> 00:07:08,630 Usually you don't want to merge your own pull request somebody on the team does it can now just say 87 00:07:09,230 --> 00:07:17,400 Merge pull request confirm merge and there you go some teams like deleting the branch afterwards so you 88 00:07:17,400 --> 00:07:18,890 can just click delete here. 89 00:07:21,020 --> 00:07:26,520 If I go back to the code, well I don't have the branches anymore because I just deleted it. 90 00:07:26,780 --> 00:07:35,110 But in my master if I go to index.html I see this is the background so now Marcy can go 91 00:07:35,110 --> 00:07:37,840 to her project and say git pull 92 00:07:40,680 --> 00:07:47,150 and again she has the latest update. 93 00:07:47,160 --> 00:07:49,970 Now let's talk about some conflicts that can arise. 94 00:07:50,130 --> 00:07:56,840 Now let's say Marcy wants to change something and I also change the same thing and we get our merge conflict. 95 00:07:57,210 --> 00:07:58,450 Let's see what happens. 96 00:07:58,470 --> 00:08:05,570 So let's say Marcy wants to change create a new feature saying we'll call this one big feature and she'll 97 00:08:05,570 --> 00:08:09,780 say git checkout or git branch. 98 00:08:09,890 --> 00:08:17,750 Big feature. She'll say git checkout big feature. 99 00:08:19,980 --> 00:08:23,490 And if I do git branch we see that there's a new branch here. 100 00:08:23,580 --> 00:08:24,820 Let's clear that. 101 00:08:24,930 --> 00:08:30,900 And she'll say here that she wants to change this back to background color or background generator because 102 00:08:30,930 --> 00:08:34,490 all the users are complaining that the title changed and they liked the old title. 103 00:08:34,500 --> 00:08:36,000 So she changed that. 104 00:08:36,480 --> 00:08:42,919 She has done the git add, git commit, 105 00:08:45,490 --> 00:08:54,560 reverting back to old title perfect and then she's gonna do git push. 106 00:08:54,670 --> 00:08:56,540 Oh let's clear the first actually. 107 00:08:57,060 --> 00:09:03,260 And we do git push. A first time you get this you might get this error saying that there's no upstream 108 00:09:03,830 --> 00:09:06,280 you just copy the code that they give you here. 109 00:09:10,770 --> 00:09:11,520 Perfect. 110 00:09:11,520 --> 00:09:12,510 Now if I go back 111 00:09:15,300 --> 00:09:23,400 to background generator I see the big feature pull request over here and just to show you that you can 112 00:09:23,400 --> 00:09:27,790 have multiple commits let's say Marcy decides to oh this is me. 113 00:09:27,810 --> 00:09:30,590 Marcy decides to add an exclamation point here. 114 00:09:30,630 --> 00:09:34,030 She can just say again she saves this. 115 00:09:34,130 --> 00:09:41,000 Let's clear she'll say git add, git commit. You do this a lot. 116 00:09:41,000 --> 00:09:51,140 So you get really really good at git after working in the company for a while and she'll say added exclamation. 117 00:09:51,430 --> 00:09:53,430 That's not what I wanted to do. Git commit. 118 00:09:55,950 --> 00:10:01,440 Commit added exclamation 119 00:10:03,810 --> 00:10:06,050 and she'll do git push again. 120 00:10:09,930 --> 00:10:13,250 And let's go back to github. 121 00:10:13,370 --> 00:10:19,790 If we look at the pull request they'll actually have both of these reverting back to old title and added 122 00:10:19,790 --> 00:10:27,800 exclamation and we see over here both of the changes create the pull request needs changes. 123 00:10:27,950 --> 00:10:28,340 Andrea 124 00:10:31,070 --> 00:10:40,780 so while this pull request is out there I decided to start a new branch called Let's just call it conflict 125 00:10:40,780 --> 00:10:41,490 for now. 126 00:10:44,390 --> 00:10:49,710 And I'll do git checkout conflict. 127 00:10:49,830 --> 00:11:02,720 And now in the conflict branch I decide to change this to just completely remove the cool generator. 128 00:11:03,180 --> 00:11:10,980 I save that again I check my status and index.html file has been changed. 129 00:11:11,410 --> 00:11:18,730 So while this is happening I get Marcey to merge the pull request. 130 00:11:18,730 --> 00:11:23,150 So she's entered it into master, her pull request is in. 131 00:11:23,200 --> 00:11:33,770 And now if I go back to my conflict and I do git status and we have to add these so git add then git commit 132 00:11:34,230 --> 00:11:35,550 I'll just do a short message here. 133 00:11:35,590 --> 00:11:49,750 Just check and now if I go back to master. Oh I have to do git checkout master again before I push my 134 00:11:49,750 --> 00:11:56,140 changes I want to make sure that I have the latest version of master so I'm not changing anything. 135 00:11:56,140 --> 00:12:02,740 I won't have any conflicts so I'll do git pull to get the latest. 136 00:12:02,950 --> 00:12:18,320 And now I go to git checkout conflict branch and I can do this command git merge master. 137 00:12:18,400 --> 00:12:25,490 So I'm saying merge whatever is in master into conflict. 138 00:12:25,720 --> 00:12:34,260 Marcy has been working on the big feature and she's merged it so now Master has the big feature branch but... 139 00:12:34,280 --> 00:12:41,830 I've also created another branch and I've been working on my own on the conflict branch and the conflict 140 00:12:41,830 --> 00:12:47,800 branch doesn't know anything about master so I'm saying hey whatever is in master right now which includes the 141 00:12:47,800 --> 00:12:49,780 big feature that Marcy worked on. 142 00:12:50,140 --> 00:12:53,610 Pull it in and make sure that there's no conflict. 143 00:12:53,620 --> 00:13:00,520 So I do that and oh-oh I get conflict merge conflict in index.html file. 144 00:13:00,850 --> 00:13:08,240 Now if I actually click on sublime text let me open this up so you can see it better oh boy I get this 145 00:13:08,840 --> 00:13:11,750 weird little syntax. 146 00:13:12,020 --> 00:13:18,910 It's overwhelming at first but it's easy to see what happening head is where my branch is at. 147 00:13:19,130 --> 00:13:28,520 And it shows me that here to the end I don't have the h1 anymore but in the master branch we have 148 00:13:28,520 --> 00:13:30,310 background generator. 149 00:13:31,290 --> 00:13:37,730 Now I can talk to Marcy and say hey Marcy do you want to keep the background generator title. 150 00:13:37,750 --> 00:13:40,930 And she'll say yes that was the right thing to do. 151 00:13:40,950 --> 00:13:42,590 Don't change the background. 152 00:13:42,600 --> 00:13:45,500 Well in that case I just remove these lines 153 00:13:49,120 --> 00:13:53,330 and remove this and save now. 154 00:13:53,330 --> 00:13:59,630 If I do git status now OK. 155 00:13:59,660 --> 00:14:01,860 We have the modified status here. 156 00:14:01,880 --> 00:14:05,010 Let me just make this smaller again so you can see. 157 00:14:05,120 --> 00:14:06,890 Let me clear this. 158 00:14:07,100 --> 00:14:12,890 What we do now is we have to do git add again because we've made those changes and we have to do git 159 00:14:13,280 --> 00:14:19,820 commit fixing merge issue. 160 00:14:20,020 --> 00:14:22,150 And I forgot the "m". Let's try that again. 161 00:14:28,030 --> 00:14:31,260 Conflict fixing merge issue. 162 00:14:31,270 --> 00:14:36,160 Let's clear here and do git status. 163 00:14:36,290 --> 00:14:38,420 Nothing to commit, working tree clean. 164 00:14:38,480 --> 00:14:44,810 And if I do git push Well again I get this error but I want to show you this time around if I do git 165 00:14:45,080 --> 00:14:48,090 push origin conflict. 166 00:14:51,410 --> 00:14:53,480 It now works. 167 00:14:53,480 --> 00:14:58,680 Let's go back to github, see what sort of things we have. 168 00:14:58,680 --> 00:15:05,670 We have the conflict branch and if we look at the conflict branch now well there's nothing changed because 169 00:15:05,690 --> 00:15:08,670 we just reverted all my changes so it's completely empty. 170 00:15:08,670 --> 00:15:18,860 There's no changes now so Marcy will be like hey did you mean to, to make this PR? 171 00:15:18,960 --> 00:15:20,150 It's empty. 172 00:15:22,030 --> 00:15:25,880 They all see this message on my PR and I can keep going. 173 00:15:25,880 --> 00:15:30,100 And that's pretty much the workflow that you'll see in git. 174 00:15:30,140 --> 00:15:33,530 I'll leave the commands for you after this. 175 00:15:33,740 --> 00:15:36,360 But it's very very nice to work with. 176 00:15:36,410 --> 00:15:42,170 You learn a few commands and as long as you have this visual model of every time you're working on something 177 00:15:42,200 --> 00:15:47,150 you always create a branch you title it with whatever feature you're working on. 178 00:15:47,720 --> 00:15:56,360 And every once in a while you want to pull master and merge master into your branch to make sure that 179 00:15:56,660 --> 00:16:00,880 you're not missing out on any updates that other developers or team mates have done. 180 00:16:01,940 --> 00:16:09,830 Once you're done with your feature you make a pull request by doing git push and that pull request. 181 00:16:09,830 --> 00:16:15,500 You'll add comments and people will review your file changes and if they want you to make a few changes then 182 00:16:15,500 --> 00:16:22,370 you can do again git add, git commit finally make your changes and then you can merge pull request and 183 00:16:22,370 --> 00:16:25,310 once that's done then everybody else on the team. 184 00:16:25,340 --> 00:16:30,230 There's now a new master so everybody else on the team should do git pull as well. 185 00:16:31,210 --> 00:16:37,300 It does takes a bit of time to get used to but is a really really nice workflow to make sure that everybody 186 00:16:37,420 --> 00:16:44,530 on the team works on the same files same projects without causing any errors and making sure that everybody 187 00:16:44,530 --> 00:16:48,850 collaborates well and that's it. 188 00:16:48,850 --> 00:16:50,280 Hope you found this useful. 189 00:16:50,290 --> 00:16:51,440 I'll see you in the next one. 190 00:16:51,700 --> 00:16:51,940 Bye-bye