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


Talk Python's Mastodon Michael Kennedy's Mastodon