Search code examples
gitbranchundelete

git undelete remote branch


I had my local directory on the develop branch, and I wanted to checkout the remotes/origin/foo/bar branch. Thanks to being an idiot with my bash command history, what I actually did was this:

git branch -a

(Note that, the remote branch doesn't exist locally yet)

git fetch
git branch -a

(Note that, the remote branch indeed exists locally now)

git branch -r -d origin/foo/bar

Stop everything, because I know what I just did.

If needed, I do indeed have other systems available, that had the remote branch checked out and fully updated. Those systems have not been touched since the remote deletion. And I can guarantee that no other developers have done a fetch or pull.

What is the solution?


Solution

  • You haven't deleted anything on your remote. Just your local reference to it. Assuming that the "server" still has it, just running git remote update origin should bring the reference back.