Wednesday, 15 October 2014

Simple, secure way to share a git repository

The problem with Windows or NFS file shares is that the contents are not version-controlled and (unless you use the Windows "available off line" feature) not available while you're disconnected from the office network. However, it is very easy to set up a git repository for a team to share code and documents, if they all have at least intermittent access to the same file share.

First install yourself a git command-line client if you have not done so yet (see

Creating the repository

Assuming that
  • You already have a local git repository called "test-repo", which you want to share
  • Your local git repositories are under %HOMEDRIVE%\%HOMEPATH%\git
  • Your shared git repositories are going to be under \\myserver\myshare\git

To add a remote copy of your own git repository to the share:

>cd %HOMEPATH%\git\test-repo
>pushd "\\myserver\myshare\git"
>git init --bare test-repo.git
>git remote add origin "//myserver/myshare/git/test-repo.git"
>git push origin master

Note that the git commands require slashes to be forward - unlike normal Windows commands.

Verify that the file .git\config within your local git repository looks something like this:

    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[remote "origin"]
    url = //myserver/myshare/git/test-repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
    rebase = true

Ensure that the sections [remote "origin"] and [branch "master"] in particular are set up correctly.

Cloning the repository

Another team member can now share your code - you both push your local commits to the shared repository and pull other team members' commits from it to your local repository. Here's what each team member wishing to access the shared repository should do, assuming that they also have their local git repositories under %HOMEDRIVE%\%HOMEPATH%\git.

>cd %HOMEPATH%\git
>git clone "//myserver/myshare/git/test-repo.git" test-repo
>cd test-repo
>git pull
>git status

The status should look like this:

# On branch master
nothing to commit (working directory clean)

Making cycling safer!

I have just been alerted to the existence of Collideoscope - a service that aims to collect data about cycling accidents and near misses directly from cyclists, and use it to press for improvements to road safety at accident black spots. What a brilliant idea. You can also use it to educate yourself about areas in which to take extra care when cycling.