Justin Chmura

Setting up Local Git Repository on Windows Server

By on

I just had the experience of getting a local Git repository setup on a Windows Server. Since this is something that I know I’ll probably do in the future, I wanted to document my steps here, not only for myself, but for anyone else that doesn’t really know where to start on getting that up and running. I’ll assume you have some basic knowledge of Git, what it is and how it works.

Install Git

The first thing to do is install Git for Windows on the server. If you visit this link, Git will automatically start downloading. Most of the options when installing it can be left as the defaults. The only choice you have to make is on line endings which you will make on this step:


Git Line Endings

I usually select Checkout Windows-style, commit Unix-style line endings. This is usually the best choice if there’s a possibility this repository will be used cross platform. That way if a file is opened using Visual Studio or some Windows exclusive editor, your new lines will be retained. If the project is exclusively Windows based, then the third option will probably be fine.

Once the setup is complete, Git is now running on your server.

Setup Network Folder

The next step is to share a folder across the network so that different people can do pulls and pushes from the repository. I recommend creating a folder that can hold multiple repositories. This way you can create as remote repositories as you want under a single point of reference for people.

After the folder is shared, anyone who wants to use the repository in Windows will need to setup a network drive on their machine. You will need to do this also to start adding files to the repository as the server repository won’t hold a working copy of the project files. I’ll go more into detail about this when the repository is initialized in the next section.

Git Init

Now that you have a shared folder to store your repos and mapped it to a network drive on your machine, the next step is to create your project’s central repository. For this, my project will be called MyProject. In the shared folder on the server, create a folder called MyProject.git. The ‘.git’ is optional, as it’s more of an indicator that this folder is a central Git hub for the project. Next you will want to bring up Git Bash and inside this new directory, run the following command:

git init --bare --shared

The ‘bare’ flag means that this repo won’t keep a working copy of the files. It will act as a hub of the change to those files. The ‘shared’ flag says this repository will be shared among many users. To be honest, I’m not entirely sure this flag is required, but it doesn’t hurt. If you want to read further on other flags, you can visit the git init documentation. After that finishes, this is what should in the directory.


Git Init

Your central repository is now up and running. This repository will only accept pushes. Since it doesn’t have a copy of the files, edits cannot be done directly to them through that repository. Someone has to clone it first.

Local Git Repository

At this point you should have a mapped network drive that has MyProject.git in it. Now it’s time to start committing files to the repo. Create your project directory anywhere you like. In that directory, you would do the normal ‘git init’ command without the flags from above. Next thing is to add our newly created shared repository as a remote in our project. Using the drive letter of the network drive, run the following command:

git remote add origin file:///z:/MyProject.git

There’s a lot of slashes but this will point our new local repository to have the remote point to the central repository.

Now you can develop as normal and push just like you would to Github, but now it pushes to your local network. It’s actually a lot easier than I had expected to get that up and running. Doing projects on Github, most of it just seems like magic. Hopefully this small guide helps you running Git on Windows Server.