Git pull rebase recovery Git pull rebase recovery

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

Published on Apr 15, 2019

Tags: git pull | Github | git

Related Posts

Did you enjoy this article? If you did here are some more articles that I thought you will enjoy as they are very similar to the article that you just finished reading.

Tutorials

Learn how to code in HTML, CSS, JavaScript, Python, Ruby, PHP, Java, C#, SQL, and more.

No matter the programming language you're looking to learn, I've hopefully compiled an incredible set of tutorials for you to learn; whether you are beginner or an expert, there is something for everyone to learn. Each topic I go in-depth and provide many examples throughout. I can't wait for you to dig in and improve your skillset with any of the tutorials below.