-1

I've removed a remote Git branch (and the local remote-tracking branch) using the command:

git push origin --delete <branch_name>

How do I undo this action?

planetp
  • 14,248
  • 20
  • 86
  • 160
  • 1
    Do you still have a local version of the branch? Does any coworker have it (locally)? – Romain Valeri Dec 20 '19 at 09:11
  • I've removed the local branch as well with `git branch -D `, but I've managed to restore it already. So just need to restore it on the remote side. – planetp Dec 20 '19 at 09:14
  • 1
    Push it up again? – jonrsharpe Dec 20 '19 at 09:14
  • If the remote has not run a GC and cleaned out the commit(s) on the deleted branch, and if the remote has any way to reference arbitrary commits and create branches or tags on them, you could use this approach if you know the old head of the branch. Unfortunately, with the little information you've posted here all we can do is provide possible things to try, and not a "do this" type of answer. Can you elaborate on what you have access to, like what kind of server is hosting the remote? github? gitlab? file share? Do you have file-level access to the server with the remote? – Lasse V. Karlsen Dec 20 '19 at 09:14
  • If you have recovered the branch locally, push it. It should be that simple. – Lasse V. Karlsen Dec 20 '19 at 09:15
  • @LasseV.Karlsen: you mean smth like `git push --set-upstream ` ? – planetp Dec 20 '19 at 09:23
  • @planetp Yes, or just redo your above command without the `--delete` flag. – Romain Valeri Dec 20 '19 at 09:34

1 Answers1

0

Push last knows local version of that branch:

git push -f origin last_known_good_commit:branch_name

amer
  • 1,528
  • 1
  • 14
  • 22