Skip to content

Instantly share code, notes, and snippets.

@ejdyksen
Created September 13, 2013 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejdyksen/6557018 to your computer and use it in GitHub Desktop.
Save ejdyksen/6557018 to your computer and use it in GitHub Desktop.
Recovering from a forced push

Make sure your working tree is clean. Stash or commit anything you're working on.

❯ git status
# On branch features/enrollment_popout
nothing to commit, working directory clean

Fetch the latest changes from the server.

❯ git fetch 
remote: Counting objects: 201, done.
remote: Compressing objects: 100% (48/48), done.
remote: Total 118 (delta 69), reused 117 (delta 69)
Receiving objects: 100% (118/118), 623.03 KiB | 554.00 KiB/s, done.
Resolving deltas: 100% (69/69), completed with 51 local objects.
etc...

Checkout the branch that has been force pushed:

❯ git checkout features/enrollment_popout
Switched to branch 'features/enrollment_popout'

Make sure you don't have any work on this branch that wasn't pushed. If you do, you'll lose the work at this step.

Finally reset the branch pointer to the value that is up on origin:

❯ git reset --hard origin/features/enrollment_popout
HEAD is now at bfd23a7 Add some placeholder validation styles
@jonahbailey
Copy link

On the checkout step, I get this:

Already on 'features/enrollment_popout'
Your branch and 'origin/features/enrollment_popout' have diverged,
and have 24 and 38 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment