18 Jun
2011

Git on Windows: Creating a network shared central repository.

Category:General PostTag: :

I was doing some basic Git training for a customer this past week and they asked about how to setup their repositories to push/pull from a network share. I thought it would be simple and we spent a few minutes in class trying to accomplish it. We stopped trying in class and I took it as a homework assignment to figure it out before the next lesson. It was a little bit of a struggle to get this working for me, so I thought I?d throw this out there for any windows developers trying to do a similar thing.

 

I tend to prefer the command line to any of the git UI tools (except when visualizing history, and diffing files). In this post I?m going to show how you can do it through a command line, but I?ll also show how you can do it with git gui which, in this case, is a few less steps.

 

How to push a local repository up to an (un-initialized) remote windows share.

 

Command Line:

I tend to run git within PowerShell, however the following set of commands cannot be run within the PowerShell prompt. If you figure out a way, I?d love to hear about it. And since I use the PowerShell prompt, I?m not sure how this would play out with the bash command.

Open a command prompt (cmd.exe) and follow the below steps to create a remote windows repository share.

CD into the context of your local repository. Say my repo was at ?C:\Code\MyGitRepo1?.

cd C:\Code\MyGitRepo1 

Next we?re going to change our current directory to the remote share location.

Something I learned during this process is that cmd.exe doesn?t allow you to ?cd? into a UNC network share path.

To get around not being allowed to ?cd? into a UNC network share we?ll use the pushd command. The reason this works is because it is actually going to map a network drive to the network share location.

pushd \\remoteServer\git\Share\Folder\Path

Now that we?re in the remote location we can create a bare git repository.

mkdir MyGitRepo1
cd MyGitRepo1
git init –bare

Your remote empty repository has now been created. Let?s go back to our local repository

popd

popd will ?CD? back to the previous location (?C:\Code\MyGitRepo1?) and also remove the network share the pushd command created above.

So we should be back in the context of our local git repo.

C:\Code\MyGitRepo1\ >

 

Now all we need to do is add the newly created remote bare repository to our local repo and push our code up.

Notice the direction of the slashes in the path below (this stumped me for a bit) 

git remote add origin //remoteServer/git/Share/Folder/Path/MyGitRepo1
git push origin master

Kind of a pain at the command prompt really, but it?s not something that?s done all that often.

Using Git gui instead:

Open up the GUI

git gui

Click the [Remote->Add] menu option to bring up the ?Add Remote? dialog.

image

Enter the name for your remote ?origin? is pretty typical for the central repository, but you can call this whatever you want. Then type the remote location. Notice the direction of the slashes.

image

Now you should be good to go.

 

Hope this helps someone else, and if anyone knows of a better/easier way I?d love to hear it.

9 thoughts on “Git on Windows: Creating a network shared central repository.

  1. I can’t recommend this, because we used this for a while and at that time we were little suspicious about performance. Then we decided install linux server into virtual environment and now work with central repository on that linux is much more faster then on share folder.

    Also we have some issues with authorization thru Active Directory to that shared folder.

  2. Thanks for the update. I’ve not actually used this technique in the wild. What perf issues were you noticing? Were they around push/pulling from the repo? Or did the local repo run slow for some reason?

  3. I was able to do this in Powershell without any problem.  The only thing that I can imagine is different was that I have Posh-Git installed.  It shouldn’t have had an impact though.

  4. I have posh-git installed also, however when I try the “git init –bare” command it doesn’t work within powershellD:CodeGitTest [master]> pushd \RemoteShareD$tempGitRepo
    Microsoft.PowerShell.CoreFileSystem::\RemoteShareD$tempGitRepo> git init –bare

    and the output I get is

    ‘\RemoteShareD$tempGitRepo’
    CMD.EXE was started with the above path as the current directory.
    UNC paths are not supported.  Defaulting to Windows directory.
    Initialized empty Git repository in C:/Windows/.git/

    Thoughts?

  5. You do not need to fiddle with pushd, just spefify the desired UNC path of your bare repo as an argument to git:

    git init –bare //computer/share/path/repo

    It will even create the “repo” directory for your if it does not exist at //computer/share/path/

    Just in case, git –version prints

    git version 1.7.6.msysgit.0

    on my system.

Comments are closed.

Find me

RSS
Facebook
LinkedIn

Disclaimer

The opinions and content expressed here are my own and not those of my employer.