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?

  • Phantom local changes showing in Git
  • How to replace an eclipse project with latest version from head using EGit?
  • git cherry-pick merge conflict pulling in other commits?
  • Updated gitignore but files still being tracked
  • data versioning with git : custom diff for specific files
  • How can I stop eclipse+git on windows from screwing with file permissions?
  • 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!

  • Remote Repository doesn't contain recent Commits
  • Using GIT with Eclipse and repos' backup
  • Error in Cloning a repository from windows
  • how to count SLOC of git library according to date
  • How to reset 'schema.rb' to last git head?
  • Git parameter pipeline script
  • 3 Solutions collect form web for “Git best-practices with Visual Studio projects”

    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:

    Of course, you can have whatever structure you want.

    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.

    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.

    Git Baby is a git and github fan, let's start git clone.