Skip to content

Trying to create a ref but getting "Object does not exist" "422" #2284

Answered by timrogers
Vanals asked this question in Q&A
Discussion options

You must be logged in to vote

👋🏻 Hi there!

If you're creating a branch using POST /repos/{owner}/{repo}/git/refs, you use the ref to set the name of the new branch and the sha to point to the Git commit SHA which should be the HEAD of that branch.

For example, if I wanted to create a branch called tim-tim-tim in octokit/octokit.js and point it to commit 37d6fd6e8f50dc75fb82e2de3e8bb70359a9b578, then I'd use the following code:

await octokit.request('POST /repos/{owner}/{repo}/git/refs', {
  owner: 'octokit',
  repo: 'octokit.js',
  ref: 'refs/heads/tim-tim-tim',
  sha: '37d6fd6e8f50dc75fb82e2de3e8bb70359a9b578'
})

Can you give that a go and let me know how you get on?

Replies: 2 comments 10 replies

Comment options

You must be logged in to vote
8 replies
@Vanals
Comment options

@timrogers
Comment options

@Vanals
Comment options

@Vanals
Comment options

@oscard0m
Comment options

Answer selected by timrogers
Comment options

You must be logged in to vote
2 replies
@timrogers
Comment options

@Vanals
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants