3

I'm attempting some git automation using php, curl and the GitHub API. I'm first merging a feature branch into the default (master) branch by creating a pull request and then merging that pull request (all via the api).

So far so good. The response I get back from the pull request merge is the sha value, merged = true and message = 'Pull request successfully merged'.

Next, I use the GitHub API to delete my dev branch. That operation is also successful. At this point in the execution, the dev branch no longer exists on GitHub when looking through the github.com UI's 'All Branches' list.

Lastly, I attempt to use the sha returned by the pull request from merging the feature branch into the master branch to create a new dev branch (as per https://developer.github.com/v3/git/refs/#create-a-reference) with the endpoint:

/repos/{owner}/{repo}/git/refs

and post data:

{"ref":"refs\/head\/{dev-branch-name}","sha":"{sha-returned-from-previous-merge"}

The response I get is: { "message": "Reference already exists", "documentation_url": "https://developer.github.com/v3/git/refs/#create-a-reference" }

This leaves me with no new dev branch. My hunch is that the sha returned from the previous merge is not the sha I should be using, but I can't find any documentation explaining where I should get the sha for creating the new branch from. As far as I can tell, the sha needed should be the one for the ref that the new branch should be branched from, so I had hoped the sha resulting from the merge of my feature branch into the default (master) branch would be the proper one. Does anyone know what I've missed here?

Thanks in advance for your help!

-axl

axl
  • 153
  • 4
  • 9
  • I'm starting in on this now in a clientside JS app, so don't have a good answer (php or otherwise) yet. But maybe you can find some help somewhere [in here](https://github.com/michael/github/blob/master/lib/Repository.js#L451-L473)? – ericsoco Sep 13 '16 at 20:55
  • Ah and there's also http://stackoverflow.com/questions/9506181/github-api-create-branch – ericsoco Sep 13 '16 at 20:55
  • Just something I noticed, the ref value should be "refs/heads/" not "refs/head/" – Joey Garcia Aug 06 '19 at 15:35

0 Answers0