Kohei Nozaki's blog 

Creating a shared git repository on local filesystem


Posted on Sunday Mar 01, 2015 at 05:04PM in Git


Tested with OS X 10.9.5.

Requirement

There are 2 users (kyle and jenkins). they want to have a shared git repository named trader on local filesystem. both of them can push changes into the repository.

Recipe

  1. Create a group named trader

    $ sudo dseditgroup -o create trader
  2. Let join kyle nad jenkins into the group trader

    $ sudo dseditgroup -o edit -a kyle -t user trader
    $ sudo dseditgroup -o edit -a jenkins -t user trader
  3. Create a bare repository

    $ cd /Users/Shared
    $ mkdir trader.git
    $ cd trader.git
    $ git init --bare --shared
  4. Change owning group of trader.git to trader

    $ cd ../
    $ chown -R :trader trader.git
  5. Make the repository writable by users in trader group

    $ chmod -R g+w trader.git

Testing

  1. Clone the repository

    $ git clone /Users/Shared/trader.git
  2. Make first commit by kyle

    $ cd trader
    $ echo 'hi there' > hi.txt
    $ git add hi.txt
    $ git commit -m 'first commit from kyle'
  3. Push to the parent repository

    $ git push origin master
  4. Switch to user jenkins

    $ sudo su - jenkins
  5. Clone the repository

    $ git clone /Users/Shared/trader.git
  6. Make first commit by jenkins

    $ cd trader
    $ echo hi there from jenkins >> hi.txt
    $ git add hi.txt
    $ git commit -m 'first commit from jenkins'
  7. Push to the parent repository

    $ git push origin master
  8. Pull the change made by jenkins from user kyle

    $ whoami
    kyle
    $ cat hi.txt
    hi there
    $ git pull origin master
    $ cat hi.txt
    hi there
    hi there from jenkins