Jonathan Wood
Jonathan Wood

Reputation: 67345

Visual Studio project folder conventions

A few versions back, Visual Studio started using C:\Users\Jonathan\source\repos as the default project folder (instead of C:\Users\Jonathan\Documents\Visual Studio 2019\Projects). I prefer the old location under Documents, but I decided to just accept the newer location because I figure that is more likely to avoid conflicts, avoid having to change it with each new release and just generally the path of least resistance moving forward.

Now I want to create a GitHub repository. But the default Local path is the same path where the project is stored! So without changing this path, I get the following error:

Repository with same name already exists at this location.

Obviously, I can change this path. But I'm trying to go with Microsoft's recommended folder locations to avoid conflicts. And so it seems ironic that I've run into a conflict using these locations!

Questions:

  1. Does anyone know why Visual Studio needs a local repository path in addition to the current project folder?
  2. Does anyone know why Visual Studio is defaulting to the same path for both? What is the intended convention for these locations?

Upvotes: 4

Views: 6714

Answers (3)

Alexan
Alexan

Reputation: 8637

VS has default project location: Tools -> Options -> Project and Solutions -> Locations:

enter image description here

and default location for git repos: Team Explorer -> Settings -> Git -> Global Settings:

enter image description here

and they should be the same because project and local repo should be in the same folder.

But you can change them what I did. You don't need to follow default MS recommendations, just select folder convenient for you.

And this answer is correct. Just select your Solution, right click and press Add Solution to source control...

Upvotes: 3

filipe
filipe

Reputation: 2047

Git needs a local repo. VS is trying to create a local repo, but you want to use the existing repo.

How do I do ?

File => Add to Source Control
View =>  Team Explorer
Sync

It will not ask to create a new repository.

Did I answer your question ?

You are dealing with "git clone" and git clone only works with an empty folder then its ok if it defaults to the projects folder, lets clone the project.

If you already have the project in your computer and just want to push the code, then you should init your local git repo in the project folder, add the github remote and push the code into the remote repository.

Here you have some docs.

Upvotes: 3

Mahmoud Shaheen
Mahmoud Shaheen

Reputation: 30

I had the same problem with Visual studio 2017 community edition. I ended up doing this.

For new projects

  • when creating a new project check "Create new Git repository" option
  • create Github empty repository
  • push from local repository to Github as remote using empty repository link

for other projects

  • clone empty github repository to folder
  • add project files
  • push to github

Upvotes: 0

Related Questions