Forked from agarwalparas/gist:d355a950148702cc7ba82abc4d1943bf
Created
July 23, 2020 22:13
-
-
Save ENvironmentSet/945e5ec5fcfd7cdca1e0deef91b234ba to your computer and use it in GitHub Desktop.
Recover Force Push on Github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First, you must get the previous commit sha, the one before the forced push: | |
## Hit through terminal | |
curl -u <username> https://api.github.com/repos/:owner/:repo/events | |
# Then you can create a branch from this sha: | |
## Hit through terminal | |
curl -u <github-username> -X POST -d '{"ref":"refs/heads/<new-branch-name>", "sha":"<sha-from-step-1>"}' https://api.github.com/repos/:owner/:repo/git/refs | |
#Finally, you can clone the repository locally, and force push again to master: | |
git clone repo@github | |
git checkout master | |
git reset --hard origin/<new-branch-name> | |
git push -f origin master | |
Credit: Sankara Rameswaran |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment