Up and Running with Git Transcripts
Chapter: Teamwork: Branches
Lecture: Techniques for paying down merge/branch debt

Login or purchase this course to watch this video and the rest of the course contents.
0:00 This idea of paying off credit card debt or branch debt as you go for feature
0:06 branches is so important and yet I get the feeling that many developers do not do
0:11 it or don't think to do it.
0:14 It's actually incredibly easy. So what I want to do is run through one more
0:18 super quick scenario now that you've seen how feature branches work and have this developer not
0:24 fall so far behind as they go,
0:28 okay so here we're going to have me working on this computer and we're going to
0:34 have over on windows, we're going to have our user over here using visual studio
0:39 code continuing on the main branch.
0:42 So this developer over here is just continuing to work stimulating like other people on the
0:47 team doing things. Meanwhile we're going to create a feature branch.
0:52 So let's go quick go back here and I do a branch.
0:56 I'll call mk better messaging something like that.
1:01 I'm gonna create a branch based on that minimize.
1:05 Now if I go to PyCharm's little branch thing it's not down here,
1:08 notice none of this stuff is here but if I do a pull now are better
1:19 messaging is here and our other one is gone.
1:21 So I want to do a check out of that.
1:24 Now notice we're on the better messaging branch.
1:29 Move this over just in case my head gets in the way we're on this feature
1:34 branch over here. Maybe we want to do some logging we'll do some print apps
1:39 starting up. Maybe we'll take this version and encode it over here too at the
1:45 top. something like this like version equals 2.1 spelling it correctly and we'll
1:56 even put the version in here like that.
2:03 Let's run and see how it's going.
2:05 Great Apps starting up version two.
2:08 So very good. That's part of our messaging.
2:10 Meanwhile over here like say let's this suppose that this line has changed.
2:17 People are coming along and saying print you know here this will be V2.1
2:24 one to it said 2.2 didn't it?
2:28 2.2. So I'm Gonna put that there.
2:31 Let's suppose we want to make the computer even more biased down here.
2:36 Where's our little bias thing? Computer roles.
2:43 And we could do two times that.
2:47 Put a little break point in here and let's just go and debug the file
2:54 and see what we get. We're debugging this and over in vs code.
3:00 Let's go to our role to a four.
3:02 There we go. We can get their names to come down and you can see
3:06 his rock paper scissors. It's but the normal than its spocks or spocks or twice
3:12 So now it's even more biased.
3:14 Right? So you know some stuff is happening And over here this person decides.
3:20 Yeah this is a great feature.
3:21 We're ready to commit it. They say now more biased even let's commit that sync
3:34 those changes and so on. So this is simulating outside of us more work has
3:42 been happening and here we're doing this and we're going to go make some more changes
3:46 let's say down here, I will say print,
3:52 she'll print like this. Print no winner yet.
3:57 Keep playing something like that. Now I could commit these changes whatever.
4:04 But as I do more work,
4:06 there's a danger that I'm going to fall further behind.
4:09 Like let's imagine one of the things I want to do seems totally reasonable up at
4:13 the top That we have this 2.2 here and we're trying to move to having it
4:17 at the top and then showing up down here but also right there if I were
4:25 to just make that change and then try to merge my feature in,
4:28 I'm going to get a merge conflict that's like waiting too long to pay off the
4:32 credit card but there's no reason that I can't be more in sync with what's happening
4:39 on the main branch. So for example,
4:41 let me just do a git pull of everything here And I can come down
4:49 to this one. It says there are incoming commits needed to pull those talking to
4:54 an update. Will do it perfect,
4:57 it updated. Okay, never use that feature before.
5:00 So now that those I've got the latest off of main on my machine,
5:04 what I can do is say I'm not ready to put this feature out yet but
5:09 I want to pay down the time difference that I've been from separated from the other
5:15 developers. So what that would mean is to take the changes that are in main
5:19 and synchronize them now. Do some more work,
5:22 take whatever new changes remain synchronized them again.
5:25 And then when I merge back I'll be way closer.
5:28 So what I can do to pay down this branch debt,
5:32 I go to Main here, it's in sync again because of what I just did
5:35 and say merge main into better messaging and hold on,
5:42 hold on, hold on. First off,
5:43 you've got to commit your changes.
5:45 So let's go ahead and say now with versioning versions specified in a variable.
5:55 Don't push I guess you can push it doesn't matter but just committed locally pushing is
5:58 unnecessary. I mean so we can go down here and merge this into Main and
6:04 look what happened. This is the change that would have been that bad debt.
6:09 This credit card does branch debt that got merged in,
6:14 this is still here. All my work is still here and I can carry on
6:17 I'm like, oh so yeah let's go ahead and change this as well.
6:20 So we use that version thing and that's good.
6:24 And then let's just do one more message print you,
6:28 I'll just call this let's call it player one that's what you're gonna be referred to
6:31 as and this will be now with more message improvements.
6:40 commit so on and let's look and see what we see here now,
6:48 fetch. Refresh yourself. So look we've got this change here but this sort of
6:56 step right there, we merged main into better messaging.
7:00 So basically previously this part right there,
7:04 that distance from here to there was the branch debt that we're gonna have to deal
7:08 with when we merge them back.
7:10 But now, because we did that point in time merge,
7:14 it's only right now, it's exactly the same.
7:18 So whenever we're ready to bring our feature branch in,
7:20 you know, maybe more changes have happened over here.
7:23 Let's see, um let's just import import sys or just some random thing at the
7:31 top. Again, it's not going to matter,
7:33 but just another main change. Let's check that in sync that refresh the picture who
7:52 you can see, we're here,
7:56 the main is there, but we're not nearly as far out of touch,
7:58 we're only that distance from here,
8:01 not all the way. So now we're ready to merge our feature branch in once
8:05 again, how do we do it,
8:08 remember? What you want to do is first make sure you're all committed over here
8:11 No, no problem. We want to be in the branch,
8:15 we're going to merge into, you can emerge in domain,
8:20 we're checking that out and then we're gonna merge.
8:22 Let's do our pull our changes.
8:26 There we go and then we're gonna emerge are better messaging one and emerged that I
8:35 guess we want to go ahead and push those changes as well over to that branch
8:39 in case we want to keep it and now we're going to say,
8:42 take that one and merge it better messaging in domain and it worked completely fine.
8:48 Wasn't there any problem? No.
8:50 This thing that might look like a problem,
8:52 just says you're not using this random thing I typed,
8:55 We got this and here just like you would expect zero merge conflicts except for what
9:00 was happening along the way. If we waited too long this this line 39 would
9:04 have been a merge conflict. So you can,
9:08 as you're working on your features,
9:10 you can just continue to merge the mainline into your feature branch as you see fit
9:16 and that's effectively paying off that branch that let's finally see the picture one more time
9:21 and then put a wrap on this chapter.
9:25 There we have it. Look at this.
9:28 So we've done a couple of merges in along the way.
9:32 This yellow one was sort of a pre payment on the debt,
9:36 I guess. This yellow, orange one,
9:38 not the red or blue, that was us pre paying down the merge debt.
9:42 So we ended up with no merge conflicts.
9:44 I encourage you to do this if it makes sense.
9:47 As long as the merging and from the main is not going to completely break your
9:50 feature, you're adding. It really makes things easier.
9:53 So you don't do a month's worth of work and then try to recombine it and
9:57 end up in a rough place.