Everything You'll Need to Know About Git

Potential Problems with Rebase

ThePrimeagen

ThePrimeagen

terminal
Everything You'll Need to Know About Git

Check out a free preview of the full Everything You'll Need to Know About Git course

The "Potential Problems with Rebase" Lesson is part of the full, Everything You'll Need to Know About Git course featured in this preview video. Here's what you'd learn in this lesson:

ThePrimeagen provides an example where two branches have conflicting changes and walks through the process of resolving the conflict by choosing the desired changes. He also highlights the potential problems and frustration of encountering the same conflict multiple times when using rebase.

Preview
Close

Transcript from the "Potential Problems with Rebase" Lesson

[00:00:00]
>> We're gonna do it again, except for this time instead of accepting ours, which is theirs, we're gonna accept theirs which is ours. Yeah, so in Hello Git let's do a plus five in remote Git, let's do a plus six. So, let's go to. Let's go to our upstream, hello-git and go and do A + 5.

[00:00:29]
A + 5, perfect. I'm gonna go to remote and I'm gonna go in here and go A + 6 6. Okay, there we go. Git status awesome, git add this, git commit a plus 6. There we go. Now we need to pull in our origin trunk and rebase on it.

[00:00:53]
So git pull rebase. Again, we have the simple conflict. We just need the result now and then remember, we're going to choose theirs which is ours. We don't want to choose ours, which is theirs. So if you open up the read me, you'll see there's a plus six, which is in the there's category.

[00:01:12]
So, erase that. Save it. There we go. We've now officially done that. We got a status We add it, if you check in status, you can see right here all conflicts are fixed. run this it's waiting for you to say that you're done, I'm gonna take this command, rebase continue, awesome.

[00:01:29]
Now, we have a chance to edit our commit message if we want to. I'm gonna keep it as A+6, awesome. So I can go git log oneline And you can see right here, there's that. Here's our previous change, and now we have the a plus six change. All right.

[00:01:47]
This is where it just gets kind of annoying. We're gonna do this a little bit. Let's just add a new line right below a plus six and hello git. Just one new line, okay? So let's go to Hello git open up the readme and go new line. Save it, git status, get add git commit, new line, go back to remote and I'm going to git pull this one in with a rebase.

[00:02:17]
Now remember rebase show. Checks out the thing I'm going to, replace the commits one at a time, and look at this. We got a conflict don't fix the conflict, just check it out. Look at that. It's like we're all over again. We're doing the exact same thing again.

[00:02:33]
We've already fixed it yet. Here's the exact same conflict again. So it can A little bit emotionally painful if you have to fix the same conflict over and over and over again. It's almost like I wish Git you could reuse recorded resolutions. That'd be really, really nice, right?

[00:02:57]
That's me saying to your face the The thing you're supposed to use, and you don't realize that I'm saying it if you don't know about it, yeah, it's like the joke, you get it, it is like right there, it's pretty funny. All right, anyway, so we see, this stinks, right?

[00:03:12]
And so we could fix the conflict, don't actually commit it, let's fix the conflict. To the point where we have A+6 plus the new line, right? So I'm gonna have to merge those changes together, right? So I'm gonna have to go delete that, delete this, and then move that one down.

[00:03:29]
Kind of stinks, right? This is where things really get crappy when you have conflicts like that, because then they get really hard to understand. All right, so we're not gonna resolve yet. By the way, does this make sense now with how rebase works? Do we all understand why this happened?

[00:03:51]
The replaying of commits where we're gonna conflict, add infinitum cuz we're just replaying something that has changing the same Plays twice, remember, it always replays one at a time.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now