32

I have computer with Windows XP and no Internet connection, only access to network drive. I'd like to set up a git repository on the network drive and then push to it from my local repository, so I can at the end of the day go to a computer with Internet connection and push from network drive to github.

My problem is I cannot access network drive from git. I put PortableGit on the network drive, but git-bash.bat and git-cmd.bat die with "CMD does not support UNC paths as current directories.". I tried replacing "cd" with "pushd" in git-cmd.bat, but it doesn't work.

BTW, I use PortableGit since I don't have admin permissions on my machine.

Any ideas?

dijxtra
  • 2,681
  • 4
  • 25
  • 37

7 Answers7

50

This worked for me:

git.exe clone "d:/dev/SDK" "//comp1/Proj/git/SDK/"
Konstantin Tenzin
  • 12,398
  • 3
  • 22
  • 20
  • 3
    and no need to map a network drive b/c from there on out, you just refer to `origin` (`git push origin master`, etc) – kelloti Mar 15 '12 at 17:46
  • 1
    ...and you can always add a remote too (if it's not already the `origin`): `git remote add remote_name "//some.network.server/git/repository.git"` – travis Nov 15 '12 at 17:21
  • 9
    Important to note is that the paths use _forward-slashes_ (`//NAME/`) not back-slashes (`\\NAME\`) – Rebecca Scott Jan 22 '13 at 01:39
  • Backslashes can work too, but you've got to escape them.: git remote add remote_name "\\\\some.network.server\\git\\repository.git". I don't know whether this is recommended or stable, but it's currently working for me on version 1.9.5.msysgit.1. – bshacklett Apr 02 '15 at 16:06
  • the proposed solution no longer works due to a regression in Git -- the use of back-slashes is only supported in newer builds because of a change to Git lib/src after 2011/2012 which converts them to forward slashes as described by this answer ... repositories that worked for me 2 years ago no longer push correctly in VS, Git for Windows, etc (but works in current/latest builds Toirtoise Git.) – Shaun Wilson Apr 19 '17 at 04:54
11

Just use the UNC path - git doesn't care what cmd can and cannot do.


Old answer: Bind the UNC path to a drive letter (or use a directory symlink).

Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
  • git over filesystem (especially windows) is painfully slow anyway. – Piers Karsenbarg Jan 23 '13 at 10:25
  • @PiersKarsenbarg It works o.k. on ntfs. Or did you mean to say something like "over _any_ networking filesystem"? Anyway, if the server actually runs Linux, using ssh instead (for cloning, you shouldn't work remotely anyway) performs much better even on Windows – Tobias Kienzler Jan 23 '13 at 10:32
  • Painfully slow in comparison to ssh. Over any filesystem, but especially Windows. – Piers Karsenbarg Jan 23 '13 at 14:24
  • 3
    This is not the answer. See answer from Konstantin Tenzin. – David Roussel Jun 17 '13 at 10:43
  • @DavidRoussel That depends on whether the repository you are committing (not pushing) to is on an UNC path or not. If it is, you still cannot `cd` to that path in order to validly call `git`. – Tobias Kienzler Jun 17 '13 at 11:36
  • @TobiasKienzler the question says "I'd like to set up a git repository on the network drive and then push to it from my local repository" – David Roussel Jun 18 '13 at 19:19
  • 2
    @DavidRoussel I understood that first paragraph as "The computer I use has a permanent network connection where I want to store the git repo and I want to push from that to the internet from another machine". Maybe I got that wrong, but in my similar case I had my university's user folder on a network share and was not supposed to use the local drive, in which case directly working on the UNC path git repository made sense – Tobias Kienzler Jun 20 '13 at 07:00
  • mapping UNC paths to a drive letter is a legacy solution. even tho cmd does not support having \\server\share as a current path there is nothing preventing it from actually working with UNC paths. Also consider the usecase with maybe several hundred servers where you want to fetch a remote git repo on each of them == mapping to drive letter is a bad solution. – NiKiZe Sep 17 '16 at 19:39
  • @NiKiZe Agreed - unfortunately I cannot change the checkmark, only OP can. Then again, I can update my answer... – Tobias Kienzler Sep 18 '16 at 17:40
6

First open a windows console, Run->cmd

pushd \\172.158.1.254\network_usb

now you should be able to 'cd' through all the directories on the drive. Optionally you can type a git init --bare nameOfnewRepo.git somewhere.

popd

Now open git bash and cd to the location where you want to clone the repo on the network drive

git clone //172.158.1.254/network_usb/pathto/nameOfnewRepo.git

Note that in git bash the slashes are forward and in the windows console backward.

MathKid
  • 1,903
  • 1
  • 21
  • 21
2

As Konstantin said, "//comp1/Proj/git/SDK/" works fine as a UNC path.

Others mentioned poor performance using a remote file system, which I cannot reproduce. Cloning the same repo took 3min45 through encrypted VPN file system access and 3min25 through unencrypted HTTP (Bonobo Git Server). The secure channel + windows authentication for repo access is certainly worth the extra 10%.

Note that Cygwin's "git" command does not work with this remote path. The git.exe that comes bundled with GitExtensions works fine, VS2015 works fine too.

0

Check if you actually have access to your local drive. Installing it there would be the easiest solution.

e18r
  • 7,578
  • 4
  • 45
  • 40
0

There's a similar (but not quite the same) issue discussed on the msysGit mailing list (and back when it was active, the issue-tracker). While that issue is about the "Git bash here"-feature from UNC, the solution might be similar. Perhaps some of these links will help you find a solution:

And if you find a solution, please consider to submit the fix back to the msysGit project :)

kusma
  • 6,516
  • 2
  • 22
  • 26
  • if Git for Windows used PowerShell instead of CMD Shell the use of "Git bash here" from a UNC path wouldn't be an issue anymore. i'm sure this could be made an install-time option, too. – Shaun Wilson Apr 19 '17 at 04:56
0

It seems that there is a register value that allows to use UNC paths on cmd. You can set up the register by running this on cmd:

reg add “HKCU\Software\Microsoft\Command Processor” /v DisableUNCCheck /t REG_DWORD /d 0x1 /f

Source