8

I have several Visual Studio solutions that have both a local repository and one on GitHub. I've already made many changes and successfully pushed those changes to GitHub.

But now Visual Studio has forgotten that one of my local repositories is associated with a GitHub repository and I can't seem to figure out how to reconnect it. In fact, it no longer lists that repository in my list of GitHub repositories.

In the image below, you can see I have a local repository called Toxic, but that repository does not appear in the list of GitHub repositories. If I try publishing the Toxic project to GitHub, it just tells me the repository already exists.

enter image description here

How the heck can I get all of my existing Github repositories to show up in the top section shown above so I can push my latest changes?

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
  • What happens if you git pull the repo? If it works, copy paste your changes and you will probably be able to push the changes. – SinOfficial Jun 26 '19 at 21:08
  • I can't pull the repo because it doesn't show up as a remote repo. – Jonathan Wood Jun 26 '19 at 21:18
  • But you know the github location of the remote repo, do you? What about cloning the repo from that location in a command prompt? – SinOfficial Jun 26 '19 at 21:22
  • Yes, I can clone the remote repository locally. But that would obviously overwrite my existing local repo. I know I can move the local repo but that seems like a pain to incorporate all my changes to the new local repo. – Jonathan Wood Jun 26 '19 at 21:30
  • You could backup the broken local repo, clone the remote repo, and then copy paste all the changed files from the broken local repo into the freshly cloned repo as long as you dont replace the ".git" folder. The only downside is that all the changes would be treated as one big commit. – SinOfficial Jun 26 '19 at 21:41
  • Yeah, I had been thinking about that. Not ideal but maybe the best I can do. – Jonathan Wood Jun 26 '19 at 21:58
  • Yeah but first i would try to fix the current repo. Can you link the remote repo with "git remote add origin [url]? Or try this: " https://stackoverflow.com/questions/18678853/how-to-fix-corrupted-git-repository – SinOfficial Jun 26 '19 at 22:02
  • In the repo folder can you run `git remote -v` and add what is the output – Tarun Lalwani Jun 27 '19 at 06:18
  • @TarunLalwani: Where do I type this? Do I have to install additional software to get the command line? Not sure if I want that. – Jonathan Wood Jun 27 '19 at 14:56
  • Try installing git and use gitbash where the toxic folder is there – Tarun Lalwani Jun 27 '19 at 14:58

3 Answers3

5

it appears the only option is to clone the GitHub repository locally, copy my modified files over the newly created repository, and then check in my changes.

Try fist:

  • installing Git for Windows (command-line)
  • cloning your remote repo in a new folder
  • adding your existing repository as a remote
  • fetching and see if you can cherry-pick your commits

That is:

 git clone https://github.com/<user>/<repo> newFolder
 cd newFolder
 git remote add old ../path/to/old/local/repo
 git fetch old
 git log old/master
 git cherry-pick old-sha1..old/master

(with old-sha1 being the first commit you want back)

Then add the newFolder in your Visual Studio workspace, and see if everything works (do a modification, add, commit and push)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
3

Unless I'm missing something, it appears the only option is to clone the GitHub repository locally, copy my modified files over the newly created repository, and then check in my changes.

Of course, I lose all my comments and iterations since the last check in to GitHub. And care had to be taken not to delete the .git folder, and to copy over all changed file and delete any that had been removed. Seems like there should be an easier way but this certainly did the trick.

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
0

I'm no git expert, but I think I might be able to help, if I'm not too late.

Run:

git remote -v

This should print something in the form of:

origin  <remote_repo_url> (fetch)
origin  <remote_repo_url> (push)

If you only see:

origin  (fetch)
origin  (push)

try running:

git remote set-url origin <remote_repo_url>

If you get no output then run:

git remote add origin <remote_repo_url>

And then try

git push -u origin

The -u or --set-upstream flag will set origin as the default repo for your branches.

Nicolas Kadis
  • 219
  • 1
  • 2
  • 10