Thursday, 16 June 2011

Shared repository using git

Revision control systems, or source code repositories, are vital for managing software development projects. But a new research project, or writing a paper, you can benefit greatly from using a repository as well. Besides the ability to revert changes or lookup the old version of a text, revision control systems allow simple sharing and simultaneous work on same files.

In this post I describe how to initialize a git repository on Windows systems using a shared drive. In my next post I will show how to share your repository using Dropbox. If you want to create a shared repository on a server with ssh access, I would refer you to this post.

Getting started


STEP 1. Download and install git client for Windows from the official website. Please check the integration of "Git Bash Here" and "Git Gui Here" into Windows Explorer, since it will make some things a lot more comfortable.

STEP 2. Connect your network drive. Open Explorer and then choose Tools->Map Network Drive...

Type in the path to the shared drive and check the box "Reconnect at logon"



STEP 3. On the network drive create a new folder for your repository. Now, click on the folder with the right mouse button and choose "Git Bash Here" from the context menu.

This will open a command line window where you have to run the command

git init --bare --shared=group

to initialize an empty repository.

STEP 4. Create a local folder in Explorer for your working copy (in this instruction I will use the folder "myrepo") and again open the command line window by clicking on the folder with the right mouse button and choosing “Git Bash here” from the context menu. In the command line window type

git clone //my/shared/drive/my_shared_repo myrepo

and hit "Enter" to clone the shared repository to your local working repository. Make sure to enter the proper paths instead of //my/shared/drive/my_shared_repo and myrepo

STEP 5. At last you need to configure git to use proper identification information:

$ git config --global user.name "Firstname Lastname"
$ git config --global user.email "your_email@youremail.com"


That's it!

General Workflow


Now you have two repositories: your local working repository with information stored in .git directory and the shared repository in the network folder. To share your repository, repeat the steps 2, 4, and 5 on other computers as well.

The usual workflow includes the following three steps:
  1. Pull the recent changes from the shared repository to get your working copy up-to-date,
  2. Make changes and commits them locally. If you are ready,
  3. Push all your commits to the shared repository to make the changes available for other users as well.

STEP 1. To pull the recent global commit and get your repository up-to-date call in your working directory:

git pull


STEP 2. To check the status of your working copy:

git status

This will show you which files were changed/added after the last commit

STEP 3. To add new files to repository:

git add filename


STEP 4. To commit changes to your local version control repository:

git commit -a -m “your message here”


Think about  putting some meaningful messages to recognize your commits later.

STEP 5. To send your commits to the shared repository:

git push