고은혜
고은혜

Reputation: 31

Git - How to revert origin remote remove

I removed origin remote in my visual Studio. I didn't know it will remove real git branches. I thought it just my local remotes.

I have to revert every remote right now. But " git log " didn't work.

Help me please.

Upvotes: 2

Views: 2417

Answers (2)

smac89
smac89

Reputation: 43068

Open git bash or something similar and navigate to the project root. Type the following:

  • git remote remove origin
  • git remote add orgin <url>, where url is the url of your git repo

then either do

  • git config --global push.default current

or

  • for remote in `git branch -r `; do git branch --track $remote; done

You can check out this answer for a way to launch the command prompt from visual studio

Upvotes: 0

Magus
Magus

Reputation: 2992

use gits built-in time machine:

git reflog

it will list of the actions you did on your local repository

copy the hash of the action before the one where you screwed up and do:

git reset --hard [paste the hash here]

there you have it, all your branches should be there again

to push them back to your repository do:

git checkout master
git push -f origin master

-f will override anything on your remote, it's optional for this case since you deleted it, but since I believe your tried to recreate it in some way and it's probably broken right now, this will force it to be an exact copy of your local branch, not you should just repeat the checkout and push part for every other branch you have locally.

Upvotes: 4

Related Questions