Collaborative Git workflow: Shared Repository on a File Server

GitHub is a great tool for collaborating on projects. However, sometimes it is necessary to mimic the “GitHub workflow” using a shared repository on a local Linux server. The following example shows how I shared an example repository with multiple users.  We are also using the Git flow model for branching, aided by the handy git flow plugin.

On my workstation

I started by creating a repo on my local workstation and setting it up to use the git flow plugin.

git init .
git flow init
git flow feature start first_feature

This created a local branch called first_feature.  I then built the feature, making commits along the way.  When the feature was finished, I ran
git flow feature finish

Create a shared repo on the server

I wanted to share my repo with colleagues, so I created a bare repository on our Linux server (part of the STOKES cluster).  All of my collaborators have accounts on this server and are part of thesame UNIX group.  The repo is located in a directory that all collaborators can access:
mkdir git_flow_test.git
cd git_flow_test
git init --bare --shared=group

It is important that everyone on the team realizes that they should NEVER work in this directory!  The only way to modify it is through git commands such as push and pull. Then, I added the bare repository as a remote.  On my workstation, I ran the command:
git remote add stokes ssh://cfinch@stokes/gpfs/fs0/repos/ARCC-Examples/git_flow_test.git
git push stokes master
git push stokes develop

Create a personal repo in my home directory on the server

Since we can’t work in the bare shared repo, each developer needs to create a local repo if they are going to develop on the server.
cd
git clone --no-hardlinks /gpfs/fs0/repos/ARCC-Examples/git_flow_test.git

Now, check out the develop branch from the shared repo:
git checkout -b develop origin/develop
Set up the git flow conventions on this repo and start working on a feature:
git flow init
git flow feature start feature3

…build your feature
…make commits as you go along
When I’m done with the feature, I finish the feature branch and push it to the shared repo:
git flow feature finish
git push origin develop

Back on my workstation

Let’s say I’ve been working on feature2 on my workstation in parallel with feature3. First, I’ll update branch my local ‘develop’ branch with Feature 3 by pulling the develop branch from the server:
git pull stokes develop
Now, I can commit and push Feature 2:
git flow feature finish
git push stokes develop

Finally, I’ll update my personal repo in my home directory on the server:
git pull

References

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.