I usually use BitBucket or GitHub to host my git repositories, but sometimes I need to host them on some internal network. In this post I will show you how to host those repositories on a Windows share.
I’m going to cover two scenarios: 1) You already have a git repository 2) You are starting fresh with a brand new repository. For both of these tracks I’m going to assume that you already have a Windows share set up on some remote computer, and that you have the read and write permissions on that share. To see more detailed information about hosting git on a server, check out section 4.2 Git on the Server - Getting Git on a Server of the Pro Git book.
I Already Have a Repository
Clone your repo (my_project
) into a new bare repository (my_project.git
):
> git clone --bare my_project my_project.git
Move the bare repository to the Windows share.
Add a remote to my_project
that points to my_project.git
. You can name your remote something other than origin
if you would like. Note that forward slashes are used, not backslashes.
> git remote add origin //{ServerNameOrIp}/{ShareName}/my_project.git
You’re all set up. You can now push
and pull
from that remote repository. If you need to clone that repo later, just use
> git clone //{ServerNameOrIp}/{ShareName}/my_project.git`
I Don’t Have a Repository Yet, I’m Starting Fresh
Create a new bare repository.
> mkdir my_project.git > cd my_project.git > git init --bare
Move the bare repository to the Windows share.
Clone the repository. Note that forward slashes are used, not backslashes.
> git clone //{ServerNameOrIp}/{ShareName}/my_project.git`
You’re all set up. You can now push
and pull
from that remote repository.