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.


    Wipe a commit from my local branch


    If you want to permanently remove a commit from your branch we can use the git reset feature. Let’s have a look.



    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: In our local repository here, we have different kind of commits. You can see here, this is the point which has already been synchronized with a remote repository. We have two further commits added on top of them.

    Let's assume that we committed them, but we changed our mind and we actually want to completely discard them. What we can do is we can copy here the ID of that commit to which we want to return.

    The important part here is don't return before the things that have been synchronized with the remote repository.

    We can use the git reset command --hard, and then basically use that commit ID. What will happen, if we execute that, and then do a git log again, is that we will now see that the first two commits have been discarded and we have jumped back to the point to which we have synchronized with the remote repository.

    Note that the --hard command here also changes your local working directory to make it point to exact the same commit. If you had unsynchronized changes or uncommitted changes still pending in your local workspace, those would be discarded.

    To avoid that, simply remove that --hard.