🎁

12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
13 : 08 : 48 : 18
Join egghead, unlock knowledge.

Want more egghead? It's 58% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 40% Off
1×
Become a member
to unlock all features
Autoplay

    Polish my git feature branch before merging or submitting for review

    Juri StrumpflohnerJuri Strumpflohner
    gitgit

    It is a good practice to commit as often as possible while you work on your personal feature branch. That helps you trace your changes as well as to have a backup to jump back to in case something goes wrong terribly. However such git branches with dozens of commits (that may not make sense) are hard to merge and review. In this lesson we’re using an “interactive rebase” to adjust our git history.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: I've been working on my app refactoring feature branch. I usually follow a best practice, which is to comment as often as possible. This is really useful. In this way, I always have a backup point in case something goes terribly wrong. I can always jump back and resume the work where I have left.

    However, as you can see, these comment messages are pretty cluttered up. For instance, here, I started to work apparently on the intro text section, then on the intro style, which seems to be a work in progress. Then here, I was probably in a hurry. I didn't even formulate nice comment message. Apparently, up here, I concluded the intro section style.

    If I want to submit this for review because my branch is basically done, then I don't want to push up all of these into a pull request. My colleagues which have to review this would have to go through all of these comments, which in the end are not even meaningful.

    Before merging or before submitting for peer review, we really want to clean up our branch into some meaningful messages and even remove some messages which don't make sense.

    In this specific case, I want to refactor here up to that app refactoring origin pointer. That was the last time I submitted to remote repository. I copy here the identifier of the comment. Then we can do a rebase interactive, which is done with the "-i." Then we basically provide here that comment identifier.

    Now we get basically representation of all the comments that have happened basically from that hash onwards. In front, you can see these keywords, which tell Git what it should do with the respective comment message. Below here, we see the various comments you have at disposable.

    Let's clean up our history. First of all, this comment here is fine. We can leave it as it is. The next one, we want to reword. We want to change here that work in progress into some more meaningful.

    The next one here, we actually want to remove in the sense of the comment message, but we want to keep the changes who happened inside there. We want to use that fixup. This is like squash, which uses the comment but melds it into the previous comment.

    We want here to really squash basically but discard also the comment's log message because it's not meaningful. I use the fixup. Here as well.

    Then we basically close our editor here. Now we go into interactive rebasing. You can see Git basically took the first comment because we said to pick it as it is. On the second one, however, it stops because said we want to reword it.

    Here, I simply want to add "Add intro section style." Then we save. All of the other comments will simply be merged on top of it. Now let's do a "git log" again. Now we can see this history is quite clean.

    We have here the "Add intro text section," which we left as it was. All of the other comments have now been merged into a single one, into a new one, which is now called "Add intro section style."