GIT repositories

Git is an open source distributed version control system.

This document describes a few basic commands commonly used when interacting with a git repository from the Linux command-line. A basic web search for “git basics” will reveal web resources that go more in depth.

  • There are two common transports for interacting with a remote git repository: http/s and ssh. This document only describes a very specific setup in the CS department for a repository using the SSH transport.
  • The CS IT admins must first setup a basic storage place for individual users to create repositories.
  • repos.cs.uky.edu is the remote host that stores the repository. The only time one should login directly to this machine is the initial setup of the repository. All other interaction should be performed remotely.

Log into repos.cs.uky.edu to run the script to create the repo space

ssh repos.cs.uky.edu

Create a repository

/usr/local/bin/csrepo -t git -n MyProject -p paul,jurek,fei

Note

The csrepo script is a simple local script written to help the initial process of setting up ACLs for the directory. There are no spaces after the commas in the user list!

This command allows the following users to make changes: paul, jurek, fei.

Only the creator of the project needs to run this command. The other team members do not. In this case, assume paul is the owner.

Import files to your Git repository

Clone the newly created repository:

git clone paul@repos.cs.uky.edu:/repos/paul/MyProject

The program prompts you for your password and then imports the directory into the repository, and it outputs something like the following.

Cloning into 'MyProject'...
warning: You appear to have cloned an empty repository.

If the clone command is issued and the repo is empty, the warning will be issued. This is normal until the repo has its first file.

The URI has a few pieces:

paul@repos.cs.uky.edu:/repos/paul/MyProject
aaaa bbbbbbbbbbbbbbbb cccccc dddd eeeeeeeee

aaaaaaa = *YOUR* CS userid, always.
bbbbbbb = the host, accessible from campus or the VPN.
ccccccc = the internal storage location, *must* include.
ddddddd = the repository owner (the user that set up the repo).
eeeeeee = the actual name of the repo.

Once the repo is cloned, the URI is stored locally so it will not be required for future git commands.

After the clone command is issued, a pre-existing file can be added as the first file of the newly created/cloned repository.

cd MyProject
cp ~/wherever/source.py      # copy a source file previously created
git add source.py            # add ``source.py`` to the local repo
git commit -a                # commit the local change, you MUST
                             # add a comment from within the editor
git push origin master       # if this is the first push to the repo
                             # you must specify a branch of ``master``

At this point the master copy of the repository has the one file and other members can now either clone the repo, or pull the change.

Checking out a file

All project members can check out the files.

git clone jurek@repos.cs.uky.edu:/repos/paul/MyProject
cd MyProject
# ....make some changes to a file
vi source.py
git add source.py
git commit -m "This is a comment on the command-line; make it useful"
git push

Other commands

git status           # local status
git pull             # pull down the latest changes from the repo

Important

Merge conflicts happen when more than one editor changes the same file and git push cannot resolve the differences. Conflicts must then be resolved manually. That process is beyond the scope of this document. Performing a web search for git conflict resolution will return a number of resources.