10

I accidently did this:

$ git push origin :development
To git@xxxxx.com:yyyyy/projects/web.git
 - [deleted]         development

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

kakarukeys
  • 21,481
  • 10
  • 35
  • 48

2 Answers2

14

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
-1

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

and..

% 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.

Bill Z
  • 1
  • 1
  • This would have helped the OP if he'd/she'd done it previously but it doesn't really answer their question, does it? – slm Apr 10 '13 at 02:16
  • What VonC was saying is very very correct for git user. What I was saying it may not work if the user has used "git push origin development:development" command to recover the lost branch. In order to guarantee the remote branch's correctness, please do not user "git push origin development:development" command to recover the lost branch, talk to git server administrator to use "fsck and git branch development sha1-1_dangling_commit_id" to recover the orginal one. – Bill Z Aug 12 '13 at 00:16
  • I still don't think this really answers the question. That's like saying "saving your work will prevent you losing it" after you've already lost it. – Craig Brett Mar 11 '16 at 14:33