Follow @endyourif rss Facebook LinkedIn

Git pull rebase recovery Git pull rebase recovery

Published on Apr 15, 2019

Using git pull --rebase is a great way to avoid those awkward looking commits of Merge branch 'development' of in the list of commits. Very difficult to read the actual deltas. Performing a Git rebase helps solve this. However, from time-to-time I've received conflicts and could not figure out how to fix the rebase and carry on. Scariest moments of my life. Luckily I've been able to recover from this.

Git reflog to the rescue

Before performing the git pull --rebase you would have committed your code locally, so it is not lost.

When you're in the awkward scenario of temp rebase branch, here are my steps of recovery:

  1. Check back out to the development branch

  2. Run git reflog

  3. Find your commit

  4. Copy the commit hash

  5. Run git reset --hard [commit id]
    Replace [commit id] with your hash.

  6. Before a regular git pull
    This leaves you with the awkward Merge branch commit, but oh well.

  7. Now push your code in git push

No code lost and you're good to go.

As a funny aside I like to pronounce "reflog" as re flog instead of ref log. Probably because I just felt like I received a good flogging...

Tags: git pull | Github | git

My Books
ASP.NET MVC 5 With Bootstrap and Knockout.js
Knockout.js Building Dynamic Client-Side Applications
20 Recipes for Programming MVC 3
20 Recipes for Programming PhoneGap
Rapid Application Development with CakePHP

Related Posts