Set remote branch to a commit we don't have locally

Some intern did a force push on master yesterday. After we’ve done scolding, 😉 we looked at the result. Luckily, we had an almost up to date version of the master on one machine, only some pull requests have to be merged again.

But one thing is bugging me: We found the old HEAD commit referenced in the last merged pull requests (on github), but since no branch or tag was pointing to it anymore, we couldn’t find any way to either pull that commit (git pull origin <SHA1> didn’t work) or to set a remote branch to that commit. Do you see any way to do that?

  • How to make existing branch an orphan in git
  • Git: how to maintain permanent parallel branches
  • Git pull on non-working branch without switching
  • Commits are left behind when branch is deleted after merge
  • What is the Git branching strategy with agile process?
  • git: how to move committed changes from master to branch?
  • Find source of mistake: git push rejected: error: failed to push some refs
  • how to push a subBranch to a branch?
  • Cordova install platforms/plugins from config.xml
  • GIT: fatal: Out of memory, malloc failed (tried to allocate 889192448 bytes)
  • Push to remote branch fails
  • How to apply unmerged upstream pull requests from other forks into my fork?
  • 2 Solutions collect form web for “Set remote branch to a commit we don't have locally”

    Assuming from your comment that you use GitHub.

    You should ask GitHub techsupport to check the reflog of your GitHub project. If less than 30 days have passed your reflog will still contain the commit you are looking for. Just pass them the hash if you know it. Ask them to reset HEAD into this commit.

    These links should be useful:

    P.S. If they give you a hint how to do it yourself – please, post it here as the answer.

    Added: This is the great link on the subject:

    If you can see the commit on GitHub, e.g. at but it is orphaned, GitHub won’t include it when you clone/fetch the repo.

    If you change the URL slightly, though, to, you can use the branch dropdown to create a branch at that commit:

    recover lost commit

    Git Baby is a git and github fan, let's start git clone.