Up and Running with Git Transcripts
Chapter: Teamwork: Merging
Lecture: Merging two change-sets together

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Back on the Mac Developer one. We've added our template rendering here. We still have the older style,
0:10 the non re factored non split apart data layer but that's fine.
0:15 Everything's working. Remember we made some changes here that we could now push over here
0:20 So this but no pending changes but in this area we could do a git push we could also do so with source tree. We open up source tree, that one's gone.
0:33 We open up funny web. It says there's one thing to push notice also though that source tree says there's two changes to pull.
0:43 Now I got to decide where is the best to show you this because PyCharm is pretty helpful. I'll try to I'll try to do the pushing PyCharm.
0:52 What's going to happen is PyCharm is going to notice that there are changes on the server and I think it will automatically try to do those.
1:00 So let's just do a push first and here and see if we can get the error. We tried to do a push and it says your push was rejected.
1:08 Why updates were rejected because the tip of your current branch is behind its remote counterpart
1:15 that's kind of obscure. But let's look at the history. What that means is, here's where the server is,
1:22 it's on origin main and this is where that Windows developer did their work and here's
1:28 where you are. You're on your main but you're too behind also one ahead. So kind of odd in that regard.
1:35 Right? We've made some changes for the template that's one of our commits but we're behind the work on the re factoring.
1:42 So you're not allowed to do your push to the server unless you are in sync or ahead. Right. This bit has to basically be behind you the origin head
1:53 So you have to be at one point in sync with a server and then only made changes on from there.
2:00 So how do we get these things synchronize how we get them working again. This is where emerging comes in so I can press call here and behind the scenes
2:12 source tree will orchestrate having git do the pull and gets to do the merge but let's try over here to do the push.
2:20 Just straight doing push because PyCharm will give us some better messages I believe. It'll say the same thing. Your push was rejected,
2:32 your remote change the remote changes. This is what the Windows developer did needs to be merged here on my machine,
2:40 you need to be emerged right here before I can even allow be allowed to push those up. So what it's going to do is pull them down,
2:48 merge them and once everything is good, it will then do what I've asked it to do. So I'm gonna say remember and just do this silently in the future.
3:00 So if you push this button it'll say you may have to try to do this Pull merge and then push your changes. So let's do that. We emerge.
3:11 It's done. Hold the stuff down, it says you've received two commits. Let's see what those are finish the new data layer and set up.
3:19 Previous code execution. Okay, that's cool. It took it a second for app.py to refresh for some reason.
3:25 But look now we have those changes automatically done. Right. This is what windows developer did and this creation of this file is what
3:34 windows developer did. But we also have the changes we made. So remember they change line three and line seven And we changed lines 12 and 13
3:48 We added this folder and this file, they added this file and git was able to see all of those operations that happened
3:58 and basically decide here's how I'm going to reassemble that to take my changes plus those changes without even asking. So that's pretty fantastic.
4:08 I guess one thing I would like to do before we move on is a quick code cleanup. Let's go ahead and do a commit on that.
4:15 You can hit the hotkey and say just a little reformatting. We don't have to look at errors and this time I can do a commit and
4:23 push all in one go and we're good. Let's look over on the server. Look, we've got finished data layer. Re factoring just a little formatting,
4:38 added HTML. All those things are coming together. We have now 10 commits now.
4:42 Normally you would see this across different people but because it's just me in different locations
4:48 you're gonna have to just imagine some of these are the Windows developer and some of these are me over here on my Mac.
4:54 But that's it. That was really low key wasn't it? We made our changes, they made their changes, they created files, we created files,
5:02 we edited the same file. They pushed their changes. We eventually pushed ours and PyCharm just said let's fix it up automatically for you
5:12 Source tree is a little more cautious. It says you tried to push those things in. We're not going to let you,
5:19 but if I push the pull the two changes it would do the merge automatically. Then I could just push the other changes back up.
5:26 You will see that there's this merger of the remote tracking branch automatically done behind the
5:32 scenes for us by the tools when we did the pull and then the push pretty fantastic
5:36 Thank you. Git, thank you for letting us all work without locking files
5:41 and blocking things and just most of the time putting it back together for us. Pretty nice.

Talk Python's Mastodon Michael Kennedy's Mastodon