- Fire up a codespace instance in the repo
- Run
gh api repos/OWNER/REPO/events > myJson.json
- The JSON that comes out is unreadable, so clean it up with
jq . myJson.json > clean.json
- Go through the json file, find the DeleteEvent where you nuked your branch, and below it, find the last push event you did to your branch. In the payload, find the head's SHA and grab it.
- Create a JSON file in this format
{
"ref": "refs/heads/YOUR_BRANCH_NAME",
"sha": "SHA_VALUE"
}
- Save the file then run this gh command
gh api https://api.github.com/repos/OWNER/REPO/git/refs --input <json_file_you_just_made>.json
This will recreate your branch.