Push current code to existing GitHub repository

Viewed 1234

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?

3 Answers

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)

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.

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.

Related