Monday, June 14, 2010

Setting up Git Repository over network UNC in windows

Git is a Distributed Concurrent Versions System (DCVS).  And as such there is no requirement for a central server which needs to be always available.

Please note this workflow may only be suitable for small teams.  For larger teams setting up a proper Git Server is probably worth the effort.

And also, It is assumed you have installed Git on all collaborating PCs.

First we need to set up a Git repository to act as a junction between collaborators.  For this, pick a box which will have reasonably high availability. But because of the nature of Git, it is not necessary for this box to be always on.

1. Open up the Git Bash (You can also use the windows command prompt. But I prefer the bash)

2. Create a new Folder for your project and set it up as a Git bare repository.
$ mkdir myapp
$ cd myapp
$ git --bare init

3.  Share the myapp folder so that it is available as read/write to all users who need to collaborate in this project.

Now that we have created a empty git repository and shared it, we need to push some code into into it. 

Go the the folder where you have the code you want to push into the server.  This may be a on the same box as the server or any box on the network. 

4. Init the Git repository there if not already done.
$ git init
$ git add *
$ git commit –m "project setup"

5. Add the remote server location to this repository.
$ git remote add origin "//server_name/myapp/"
$ git push origin master

Now we have setup the server and pushed some code into it, We have to setup other users to get the initial code and start committing changes.

6. The following needs to be done on all developer PCs which need to collaborate on this project.  Make sure these users have read/write UNC access to the server project folder.
$ git clone "//server_name/myapp"

7. So all the setting up is done now. Now you can start coding, commit changes and push your code to the server.  So after you have done your code changes,
$ git add *
$ git commit –m "my changes"
$ git push origin master

And if you want to get latest changes from the server,
$ git pull origin master

Please report errors and omissions.

Happy Coding!