Join egghead, unlock knowledge.

Want more egghead?

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

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Polish my git feature branch before merging or submitting for review


    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.



    Become a Member to view code

    You must be a Pro 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
    orLog In




    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."