libgit2sharp what is correct sha to supply to GitHub API merge pull-request?

GitHub API requires merge pull-request to be submitted as

PUT /repos/:owner/:repo/pulls/:number/merge

with request body json

  • Git Push clarification - What gets pushed?
  • Easy way to pull latest of all git submodules
  • Newbie in Heroku: Error when push my app to Heroku
  • `git stash` during a merge conflict
  • Can I undo the last git push?
  • Is there a VIM Git timeline?
  • {
      "commit_message": "blah",
      "sha": "{SHA that pull request head must match to allow merge}",

    Following a commit, push, create PR, what libgit2sharp property supplies the correct sha ?

    For the current branch, it appears Branch.Tip.Sha is the correct value, but I’m receiving response error :

    { “message”: “Head branch was modified. Review and try the merge
    again.”, “documentation_url”:

  • tortoisegit clone option is unavailable in right-click context menu
  • How to keep git from changing file ownership
  • Persuading git to handle symlinks correctly on vboxsf filesystem
  • What is the alternative to using --process-dependency-links with pip
  • Warn when doing git commit -a if something is staged
  • remove all binary files recursively from git repo and commit history
  • One Solution collect form web for “libgit2sharp what is correct sha to supply to GitHub API merge pull-request?”

    Two different commits and shas come into play when it comes to Pull Request.

    When leveraging the GitHub API to merge an opened Pull Request, the optional sha property from the json payload is expected to match the sha of the branch tip as currently known by GitHub.

    Provided your local repository is in sync with what GitHub knows about your repository, this should definitely be matching what repo.Branches["your_topic_branch"].Tip.Sha returns.

    Note: In order to ensure that the GitHub known head of the PR matches your local branch tip, using LibGit2Sharp, you can retrieve GitHub PR merge/head pointed at commits, by directly fetching a special reference namespace. The following code demonstrates this

    var remoteName = "origin"; // or whatever your remote is named
    var remote = repo.Network.Remotes[remoteName];
    var prNumber = "1123"; // or whatever your pr number is
    // Build the refspec
    string refSpec = string.Format("+refs/pull/{1}/*:refs/remotes/{0}/pull/{1}/*", 
                            remoteName, prNumber);
    // Perform the actual fetch
    repo.Network.Fetch(remote, new[] { refSpec });
    Console.WriteLine(repo.Branches[string.Format("pull/{0}/merge", prNumber)].Tip.Sha);
    Git Baby is a git and github fan, let's start git clone.