2

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.

고은혜
  • 31
  • 5
  • I suspect that the remote branches are still there. Can you try just creating a new remote pointing to the same URL as before? – Tim Biegeleisen Jul 18 '16 at 02:20
  • All of branches are removed In Git site... I can't find other branches except for dev( this is default branch ). – 고은혜 Jul 18 '16 at 02:24
  • You might be able to resurrect the branches locally, then push them back out to your provider (e.g. Bitbucket, GitHub). Look into using the reflog. All your most recent commits on branches should ideally still be there. – Tim Biegeleisen Jul 18 '16 at 02:25
  • problem is that I removed other people branches. In "git reflog", I can't find recent commit by other people. How can i revert deleted branches what I haven't ever used. – 고은혜 Jul 18 '16 at 02:32
  • Your friends could also bring their branches, even more easily, if they still have them there locally. In the future, don't delete things so quickly. – Tim Biegeleisen Jul 18 '16 at 02:35
  • I don't want to bother coworkers. Maybe there are local git... Then, There is no solution that I can solve alone? – 고은혜 Jul 18 '16 at 02:38
  • Come to think of it, It is not a big problem. Thank you for your comment!! – 고은혜 Jul 18 '16 at 03:14
  • Well, maybe it is a big _potential_ problem, but it's really hard to screw things up in Git permanently. Actually, usually you have to go out of your way to do that. Glad to help! – Tim Biegeleisen Jul 18 '16 at 03:16

2 Answers2

4

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.

Magus
  • 2,905
  • 28
  • 36
0

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

Community
  • 1
  • 1
smac89
  • 39,374
  • 15
  • 132
  • 179