Git best practices with Visual Studio projects

I want to use Git for some of the personal projects I'm working on. I am new to Git and don't know how to start ...

Should I first create a project (for example, an ASP.NET MVC application) in Visual Studio, and then rotate the folder created in the repository, or first create a repository and then create a project inside this folder?

Also, are there any recommendations for structuring folders inside the "repository root folder"?

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

+6
source share
3 answers
Storage facilities

Git is so light that it really doesn't matter if you create a project and then create a repo or create a repo and add folders. In any case, you will do git add and git commit after creating the folders.

But for me, I usually create a project from VS and restructure the folders, so in the root folder src and .sln and the project files are in the src folder. VS usually creates a root folder with the project name, which I rename to src. Then I create the repo, add the standard .gitignore and .gitattributes and .gitattributes repo.

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

Of course, you can have any structure you want.

+3
source

Organize your files and folders, however, starting with 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 these steps.

  • Create an empty repository.
  • Clone an empty repository locally.
    • add .gitignore etc. and make the initial commit.
  • Create a VS project in a different folder.
  • Then I do one of the following.
    • copy the files from the .git repository to the VS solution folder, which changes the location of the local repo.
    • close VS, copy the solution files to the local repository, and then open VS again.

I really need to spend time to automate it, but I spend more time working on existing projects than starting over again, so he has not been very annoyed so far.

I tried all visual git tools, including those that integrate with VS, but always end up using PowerShell instead - this is just a matter of preference. Try it, they can work well with your workflow.

+3
source

For use in VS you can use Git extensions . It integrates into the IDE and provides a nice graphical interface for basic Git operations.

As for the folder structure, it depends a lot on the project, so there is no answer here. There is no better practice than an organization based on how you work!

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

+2
source

All Articles