Reader small image

You're reading from  Git for Programmers

Product typeBook
Published inJun 2021
PublisherPackt
ISBN-139781801075732
Edition1st Edition
Right arrow
Author (1)
Jesse Liberty
Jesse Liberty
author image
Jesse Liberty

Jesse Liberty is a full-time hands-on programmer, specializing in C#, git and .NET MAUI. He hosts the popular Yet Another Podcast and is the author of more than a dozen best-selling programming books. Liberty is a Certified Xamarin Developer, a Xamarin MVP and a Microsoft MVP. He was a Technical Evangelist for Microsoft, Distinguished Software Engineer at AT&T; Software Architect for PBS and Vice President of Information Technology at Citibank, and he was on the teaching staff at Brandeis University. Jesse is a recognized expert and has spoken at conferences world-wide.
Read more about Jesse Liberty

Right arrow

You messed up the remote by pushing a broken branch

If (and when) you break the Master branch by pushing an incomplete and broken local copy, dry your tears, take heart! This can be fixed.

Note, this should not be possible. If you are using Azure DevOps (or something similar) your pipeline should not accept any merge that doesn't compile (and arguably pass a set of unit tests). But I digress…

The first command you want is:

git reset --hard <remoteRepository> / <Yourbranch>@{1}

That resets your local copy of <Yourbranch> to the last synchronized version of <remoteRepo>. Thus, if your branch is Feature1 and it is on origin, you would write:

git reset --hard origin/Feature1@{1}

Now you want to restore the remote repo to its state before you broke it:

git push -f <remoteRepository><Yourbranch>
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Git for Programmers
Published in: Jun 2021Publisher: PacktISBN-13: 9781801075732

Author (1)

author image
Jesse Liberty

Jesse Liberty is a full-time hands-on programmer, specializing in C#, git and .NET MAUI. He hosts the popular Yet Another Podcast and is the author of more than a dozen best-selling programming books. Liberty is a Certified Xamarin Developer, a Xamarin MVP and a Microsoft MVP. He was a Technical Evangelist for Microsoft, Distinguished Software Engineer at AT&T; Software Architect for PBS and Vice President of Information Technology at Citibank, and he was on the teaching staff at Brandeis University. Jesse is a recognized expert and has spoken at conferences world-wide.
Read more about Jesse Liberty