7

I'm using Visual Studio 2013 with the MS Git plugin. I'm trying to add an existing project to source control on my machine. The project is an empty project with one file. The path to the project solution is C:\_Projects\HelloGitWorld\HelloGitWorld.csproj - according to the git settings, I created the default repo location, but it doesn't seem to be storing the repo there (I tried this for other projects as well, and it created the repo in the same location as the solution).

So I basically right-clicked on the solution and chose 'add to source control'. This is simple enough, and as soon as I do that, I get:

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

I realize you can do this through git bash as well, and I will eventually move onto that, but right now I just want to add a local repo for this. Why won't it let me? Where is this trying to create a path that is too long?

Hatjhie
  • 1,366
  • 2
  • 13
  • 27
M.R.
  • 4,737
  • 3
  • 37
  • 81
  • Had that problem before, and the environment variables were messing around %temp%, %usertemp%, and others. Check this post about TFS, probably help you. http://social.msdn.microsoft.com/Forums/vstudio/en-US/1638a5f0-9321-4ff9-9ee7-6d347badb972/please-some-solution-to-the-specified-path-file-name-or-both-are-too-long?forum=tfsbuild – celerno Jan 30 '14 at 23:11
  • Thats for TFS, not Git. Probably similar issue, but I need the info for Git. – M.R. Jan 30 '14 at 23:31
  • I want the VS integration to work, but I still prefer SmartGit. The VS integration caused terrible slowdowns and various problems when I tried it. – Brian MacKay Feb 12 '14 at 21:32

2 Answers2

4

Even though you create a project under your "default repo location" this does not mean a Git repo will be created for you. You need to create (or clone) a Git repository BEFORE creating a project/solution, or use the "Add to Source Control" option to ensure a new repo is created for you.

The "default repo location" is not a Git repo, and a solution folder is not (by default) a Git repo.

The real purpose of VS's "default git repo location" is so that VS tooling can locate any repositories you have cloned locally. It will search the immediate folder you specify and (I believe) any sub-folders. Any folders recognized as Git repository roots will then appear in the list of Repos in the 'connect' page of Visual Studio UI.

If you want to use the command-line this page on git-scm.com has a small snippet which shows how you could create a folder and initialize it as a git repo (locally.) Here is an example showing how to initialize your solution folder as a new, local Git repository from powershell (with msysgit installed):

set-alias git "C:\Program Files (x86)\Git\bin\git.exe"
cd "C:\_Projects\HelloGitWorld\"
git init
git add .
git status

From there you can launch visual studio, load your project/solution and see that git integration is now working as intended. The same set of commands can be executed from a CMD shell, but you will probably have to specify the full path to git, or just use git bash (which may be obtuse for you if you're not accustomed to using unix shells.)

If you don't want to use a command-line tool you can use Visual Studio Tools for Git and select "New.." from the "Connect to Team Projects" panel (thanks to Edward Thomson for pointing this out), or use a third party tool such as TortoiseGit. This will simplify the creation of a git repository without requiring you to understand how Git works, nor how to work with a command-line. For most simply scenarios you can rely entirely on Visual Studio Tools for Git. No need for anything third-party.

I use visualstudio.com and github.com for project hosting, as well as bare (private) repositories on a secure SAN at my home (since, in the end, you can't trust anyone anywhere with your private works. I don't care what people say.) You might find this article on saintsjd.com helpful in deciding if a bare repo is what you're really after, and this guide on stackoverflow to see how to create one yourself.

Let me know if I can clarify anything, or if you need some examples.

Community
  • 1
  • 1
Shaun Wilson
  • 8,727
  • 3
  • 50
  • 48
  • You can create a new repository in Visual Studio, just select "New" in the "Local Git Repositories" section of the Team Explorer Connect page. – Edward Thomson Feb 13 '14 at 22:16
  • Oh, snap. Not sure when that was added or if I actually managed to overlook it this entire time (I've been using VS tools for Git almost since it was made public.) I like that it includes a default .gitattributes and a .gitignore file. It would be nice to see a feature to add/edit/remove and select remotes, unless I'm overlooking that too, it's the only other thing I have needed since it was launched (but lacked and thus still rely on command-line tools.) – Shaun Wilson Feb 13 '14 at 22:51
  • Totally agree - I'm not sure where this is on the priority list, but it would be very nice to manage remotes easily. – Edward Thomson Feb 13 '14 at 22:56
0

You've mentioned MS Git plugin - why you use it when VS2013 supports Git by default? I'm using standard VS2013 Git integration + Git for Windows to sync my solution with Bitbucket and it works fine. I also saw this strange default repo location setting, but all Git repos are actually placed inside .git folder under my solution when I use a solution context command "Add to source control..." (at this point you may create your Git repo from scratch). And actually .git folder + .gitattributes and .gitignore files are your local git repo which you may or may not sync with external hosted Git repo such as Bitbucket and Github. If you want to remove Git binding for you solution just remove mentioned folder and files.

As for the long path error you may check your actual solution path in Solution Explorer (select Solution root element and press F4).

Here are couple of links which may help you to get started:

It's worth mentioning here that if you're looking for a free hosted private Git repos then you might want to go on with Bitbucket (private repos are free for teams up to 5 people). If a small fee for private repos does not distract you then you might want to go on with Github which is the biggest Git repos hoster. Disclaimer: I'm not affiliated with Bitbucket and Github in any way, it's just a result of my personal investigation.

Also I must admit that I'm not a fan of command line tools so my solution is good if you don't like them also.

Community
  • 1
  • 1
IPSUS
  • 499
  • 4
  • 15
  • I do contracting for a company that uses github for private repositories. The company chose github because of their analytics/graphs and collaboration tools (issue tracking, code browsing and commenting, pull requests, etc.) Private repositories on github aren't free, however, but they do offer them. – Shaun Wilson Feb 13 '14 at 21:33
  • @Shaun Wilson, thanks for the comment. I'm aware that Github does not offer private repos for free - that's why I chose Bitbucket for my not-so-commercial projects. As for the issues tracking and other project management stuff then Bitbucket offers various tools like Jira, Confluence etc. but unfortunately not for free. – IPSUS Feb 14 '14 at 07:57