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.
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?.
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.
Now that we?re in the remote location we can create a bare git repository.
git init –bare
Your remote empty repository has now been created. Let?s go back to our local repository
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.
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
Click the [Remote->Add] menu option to bring up the ?Add Remote? dialog.
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.
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.