haagel
haagel

Reputation: 2728

Git best-practices with Visual Studio projects

I want to use Git for some personal projects I work on. I'm new to git and don't know how to start...

Should I first create the project (say an ASP.NET MVC application) in Visual Studio and then turn the folder that is created into a repository, or should I create a repository first and then create the project inside that folder?

Also, are there any best-practises for how to structure the folders inside the "repository root folder"?

These are my two questions right now, but any pointers to articles etc for best-practises using Git and Visual Studio are welcome!

Upvotes: 11

Views: 9174

Answers (3)

David Culp
David Culp

Reputation: 5480

Organize your files and folders however makes since to your project and workflow, git doesn't care how the files are organized.

Since Visual Studio complains when I try to create a project in an existing folder, I follow the following steps.

  1. Create a bare remote repository.
  2. Clone empty repository locally.
    • add .gitignore, etc. and make initial commit.
  3. Create VS project in a different folder.
  4. Then I do one of the following.
    • copy the files from the .git repository into the VS solution folder -- which changes the location of the local repo.
    • close VS, copy solution files to local repository and then reopen VS.

I really should take the time to automate it, but I spend more time working on existing projects than starting anew so it hasn't been much of an annoyance yet.

I've tried all the visual git tools, including those that integrate with VS, but always end up using PowerShell instead -- just a matter of preference. Give them a try, they may work well with your workflow.

Upvotes: 5

manojlds
manojlds

Reputation: 301507

Git repositories are so lightweight that it doesn't really matter whether you create the project and then create the repo or create the repo and add the folders. You will anyway be doing a git add and git commit after the folders have been created.

But, for me, I usually create the project from VS and restructure the folders so that at the root there is the src folder and the .sln and project files are within the src folder. VS would typically create the root folder with the project name which I rename to src. Then I create the repo, add the standard .gitignore and .gitattributes and commit the repo.

See my preferred structure here: https://github.com/manojlds/cmd

Of course, you can have whatever structure you want.

Upvotes: 5

CharlesB
CharlesB

Reputation: 90496

For using in VS you can use Git extensions. It integrates into the IDE and provides nice GUI over the basic Git operations.

As for the folder structure, it depends so much on the project, so no answer can be given here. There's no better practice than organizing based on the way you work!

As for the moment of repo creation, just create it as early as possible, so I'd say first create it and then add your project.

Upvotes: 5

Related Questions