Developing on Staxmanade

Git on Windows: Creating a network shared central repository.

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.

Comments

Jason.Jarrett
Thanks for the nice comment. In regards to your question, I'm afraid I'm not familiar enough to be of help.

You might take your question over to StackOverflow.com as there are some very smart people over there that might be able to help.

Good Luck
Djilali Tabbouche
Hi Jason, thanks for your post.
I'm using this exact setup to deploy applications to both linux and windows server.
No problem on linux using ssh and pushing to windows throuh network shares works fine but I have one issue with post-receive hooks: I use this hook to checkout the remote repository to the application directory and run configuration tasks and on windows, the git command use the local computer environment (git-dir and work-tree).
I've tried every options without success.

Any idea?

Comments