This message was deleted.
# how-do-i
s
This message was deleted.
g
That might not be the right
git
command, also...
j
GH doesnt garbage collect the shas, thats how we're able to show the diff. i think there is a different way to call fetch for raw shas, as it looks here like git thinks you're looking for a ref
n
I've done this before in the past
Copy code
gh api /repos/OWNER/REPO/git/refs -f ref='refs/heads/<new_branch_name>' -f sha='commit-sha-to-restore'
It will create a new branch with that sha
g
Thanks for the help. The
gh api
command succeeded (and if I run it again it complains
"message": "Reference already exists",
) but I don't understand how to grab the result. I do not see a new branch on the repository.
n
you don't happen to have a fetch filter do you? you should also be able to see the branch on the github web interface
i guess i should say you need to do a
git fetch
to see the branch locally first
g
I don't see the branch on the Github UI 😐
Copy code
$ gh api /repos/ORG/REPO/git/refs -f ref='refs/head/gng-20231207' -f sha=09491a0921749a8674112a55238210ea6e7ff6cd
{
  "ref": "refs/head/gng-20231207",
  "node_id": "REF_blahblahblah",
  "url": "<https://api.github.com/repos/ORG/REPO/git/refs/head/gng-20231207>",
  "object": {
    "sha": "09491a0921749a8674112a55238210ea6e7ff6cd",
    "type": "commit",
    "url": "<https://api.github.com/repos/ORG/REPO/git/commits/09491a0921749a8674112a55238210ea6e7ff6cd>"
  }
n
not sure it works on my end šŸ˜ž
Copy code
āžœ  git:(main) gh api /repos/<OWNER>/<REPO>/git/refs -f ref='refs/heads/gng-20231207' -f sha='814a4f9fe04460b64613452b0e111eecfbc6c645'
āžœ  git:(main) git fetch
remote: Enumerating objects: 1, done.
remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 1
Unpacking objects: 100% (1/1), 564 bytes | 564.00 KiB/s, done.
From <http://github.com:<OWNER>/<REPO|github.com:<OWNER>/<REPO>>
 * [new branch]      gng-20231207 -> origin/gng-20231207
oh you have
refs/head
and I have
refs/heads
g
I knew I needed to be copy-pasting. Thanks for the catch
n
you may be able to clean up the
refs/head
reference with, https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#delete-a-reference but they may lock it down