how to undelete a deleted remote branch

I accidently did this:

$ git push origin :development
 - [deleted]         development

How do I undo? What is the second best thing I can do?

  • How to organize different parts of project in git repo?
  • Including 3rd Party Non-GitHub Libraries in GitHub
  • Git: Files in vendor are not found
  • Xcode merge two branch Git
  • Undo a git merge when it has been pushed
  • How can I use git as the scm provider in sonarqube 5.0 ( using sonar-runner )
  • GIT - how to enforce file exclusion by server?
  • Un-ignore all files in global .gitignore
  • git merge different repositories?
  • What git branch was I just in?
  • How to delete a commit on a git remote?
  • Git checkout and reset on Windows occasionally shows random files have changed
  • 2 Solutions collect form web for “how to undelete a deleted remote branch”

    If your branch was fairly up-to-date with the remote one, a simple:

    git push origin development:development

    should be enough, as illustrated by this thread.
    If not, a local action needs to be done on the remote server side (through reflog or fsck) to retrieve the branch HEAD SHA1 id and checkout it again.

    I have been looking for the method to recover the deleted remote branch for long time.
    I have just found that you can use:

    % git clone –mirror your_remote_repo_url


    % git fetch

    As long as you have run “git fetch” before you deleting the branch,the branch you deleted will be fetched. The behaviour match the git server bakup default rules.

    … in the mirror repo to backup your remote repo. The backup repo will keep all branches including the ones you deleted.

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