Git is a distributed version control software (DVCS) which allow its users to manage changes in a code base in a collaborative manner. One of the main characteristics of DVCS systems is that each user keeps their own copy of the repository, so they work separately and unify the changes whenever desired. This is a tutorial on how to set up a git repository on the Unix timeshare computers at UCSC for shared use in a group project. This document assumes basic knowledge of git and Unix (shell, ssh).

Creating the repository

First log into your UCSC account at the Unix server. For the remainder of this document we are going to assume a user name of sslug:

ssh sslug@unix.ucsc.edu

Once inside your home directory, create a folder to store your git information. It is not required, but it is good practice to create a folder to store all repository folders. The repository folder will be kept free of work files to allow pushing from another computer. We are going to create a repository named test.

mkdir ~/git/test.git
cd ~/git/test.git
git init --bare

The repository exists now, but it still needs to be populated, and access permission for other users have not been set yet.

Populating the repository

This part depends on whether we have an existing code base, or we are going to start one now.

With an existing code base

If we have an existing repository, we have to navigate there and set up our newly created repository for upload (if we don’t we can create a git repository there and populate with the source files). The steps here will be executed on the local machine, not the Unix timeshare.
First we move into the local repository (we use the same name for the folder as the repository, but that is not required):

cd ~/path/to/repository/test

Then we add a remote pointing to our previously created repository

git add remote origin sslug@unix.ucsc.edu:git/test.git

We can now upload all the data from our existing repository:

git push origin master

Without an existing code base

In this case we are going to create a folder to store the repository.
First we move to the folder that we want to create your repository folder in:

cd ~/path/to/repositories_folder/

Then we call git clone to copy the repository:

git clone sslug@unix.ucsc.edu:git/test.git

This will create a folder named test, which can be used normally for code development with git control.

Sharing the repository

For this step it will be necessary to possess the usernames of the other users of the repository. We are going to use wcoyote and bdeer for our example. We can add write permissions for both users with the following command:

fs setacl ~/git/test.git wcoyote write bdeer write

If we added a user by mistake and want to remove them, we can do so with the following command:

fs setacl ~/git/test.git wcoyote none

Notice that we can use the same command fs setacl with one or more users, we just have to repeat the permissions after each user name. The documentation man fs_setacl explains this command in more detail. If we want to check what permissions we have set, we can check with the following command:

fs listacl ~/git/test.git

Once we have permissions configured, the other user can clone the repository with the command. For that we are going to need the full path for sslug home directory, which can be obtained by that user running the command cd; pwd.

git clone bdeer@unix.ucsc.edu:/afs/cats.ucsc.edu/s/sslug/git/test.git

From there on both users can collaborate using this repository as a common point of access.

Tips

  • There are many different interfaces for git that can improve user experience. This tutorial focused on command line, but any decent interface should be able to achieve the same results.
  • One of the biggest source of problems in git are merge conflicts. A suggested workflow is to create branches for modifications and update the master branch before merging those modifications. Tools that help with the merging process are also a good learning investment.
  • Be careful of using internet solutions to git. Git is powerful, but that power also allows the user to make irreversible modifications. Before copying and pasting a git command from the internet, be sure that it won’t destroy your work. If unsure but desperate, at least make a backup of the repository. The D in DVCS stands for distributed.

References

UCSC AFS Quick reference http://its.ucsc.edu/unix-timeshare/tutorials/afs-quickref.html#fsacl
Git https://git-scm.com/