简体   繁体   中英

In Visual Studio 2019, can I set my local source control repository to somewhere other than in my solution folder?

Visual Studio 2019 Community, Win10 Pro 64

I'm new to VS 2017 and 2019 and not all that familiar with git, but I have been able to set up a git repository and commit my solution to all the way to the remote server, using VS. If I understand this correctly, the files are first stored into a repository that exists on my local machine, and then I commit it to the repository on the git server.

While this all works just fine, I can't figure out how to place that local repository somewhere other than in my solution folder. When I click on File->Add to Source Control in VS, it always adds it in a .git folder in my solution folder, and I can't figure out a way to put it somewhere else.

The reason I want to do this is that I do my development on an SSD for speed, but I want my local repository on an HDD so it doesn't consume space on the SSD.

Is there any way to set this up with Visual Studio 2019?

You can do nothing from VS but you can do it by relying on the command line. Once it is set, you could you VS normally without problems.

There is a way to set the '.git' folder in another directory when you init or clone a repository. See: https://stackoverflow.com/a/19548676/717372

But you could also easily achieve what you want using the 'git worktree' feature.

Do the steps :

  • Verify that all the files are committed or stashed (you have a clean working directory)
  • move all the folder on your hdd.
  • From inside the new hdd directory, checkout a revision (the one you wish, but not a branch, to avoid a limitation due to use the 'worktree' feature) with git checkout SHA1_OF_HEAD or git checkout $(git rev-parse HEAD)
  • Create and use a worktree on your ssd with git worktree add c:\\path\\to\\ssd master
  • Now you can work in the ssd folder from VS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM