Working With Private Repositories in Athens Development Servers Using Git HOWTO
Working With Private Repositories in Athens Development Servers Using Git HOWTO
Introduction
The purpose of this document is to introduce software engineers to the use of
private repositories in Athens development servers using git. The document will go
through the repository creation, the repository cloning in a local repository for each
user account and also will demonstrate use cases, such as reviewing committed
code, committing new code, reverting commits, handling merge conflicts etc. As a
prerequisite, all the involved engineers should have a valid account in the following
Athens development machines:
caladan
10.158.67.81
hyperion
10.158.67.84
arrakis
10.158.67.85
What is git
Git is a version control system (VCS), but what is a version control system in first
place. Version control is a system that records changes to a file or set of files over
time so that you can recall specific versions later. A VCS allows you to: revert files
back to a previous state, revert the entire project back to a previous state, review
changes made over time, see who last modified something that might be causing a
problem, who introduced an issue and when, and more. Using a VCS also means
that if you screw things up or lose files, you can generally recover easily. Git was
designed and implemented by Linus Torvalds for Linux kernel development in 2005
and since then has become the most widely adopted VCS for software development.
More information about the history and the use of git can be found in [1], [2], [3].
Using git
The general use case scenario is about having a small development team that is
working on a project for which they would like to use a git repository. For clarity, we
are going to use an imaginary team, consisted from nikos, anna and george which
all have valid accounts to the Athens development servers.
$ cd repositories/1stProject.git
$ git init --bare --shared=group
# Initialized empty shared Git repository in repositories/1stProject.git/
$ ls
# config HEAD hooks objects refs
Now all developers in the team, should have read and write access to the shared
repository that nikos created since they all share the same group in Athens
development servers (hostingusers_cic_athens). Note that nikos must create a bare
repository every time a new project is to be added.
Git clone
nikos, anna and george should now clone the 1stProject shared repository from
where is located, ie repositories/1stProject.git in nikoss home directory. nikos
should use the following commands to clone the 1stProject repository in any of the
Athens development servers /scratch directory, for example /scratch directory in
hyperion is used below. Note all Athens development servers use the same home
directory per user, but different scratch directory.
nikos@hyperion
$ cd /scratch/nikos
$ mkdir 1stProject
$ cd 1stProject
$ git clone /home/nikos/nameOfProject.git .
# Clone messages
Since, this is an empty repository, nikos can commit the first file of the repository,
for example a README file.
nikos@hyperion
$ cd /scratch/nikos/1stProject
$ echo 1stProject README file > README
$ gia add README
$ git commit m Adding a README file
$ git push origin master
# Commit messages
$ git log
# commit b989d6e18f2b1e1ccf7614d6e76128071f8b20eb
# Author: Name=nikos <[email protected]>
# Date: Tue Jul 8 12:17:55 2014 +0300
#
# Adding a README file
Now anna and george can clone the 1stProject repository in their /scratch directory
in any Athens development server, for example:
anna@arrakis
$ cd /scratch/anna
$ mkdir 1stProject
$ cd 1stProject
$ git clone /home/nikos/nameOfProject.git .
# Clone messages
$ git log
# commit b989d6e18f2b1e1ccf7614d6e76128071f8b20eb
# Author: Name=nikos <[email protected]>
# Date: Tue Jul 8 12:17:55 2014 +0300
#
# Adding a README file
Now all team can work to the same shared repository through their local repository
in /scratch/$USER/1stProject directory.
Note that each user has created a local
repository and only by pushing/pulling commands, the shared repository
(/home/nikos/repositories/1stProject.git)
and
the
local
repository
(/scratch/nikos/1stProject) can remain in sync. More info about the push/pull
commands can be found below.
Reviewing repository
The command git log can be used to review the repository. The command has many
options (see git log --help) but the handiest are:
$ git log
$ git log --stat
$ git log p
#default output
#see affected files per commit
#see code differences per commit
nikos@hyperion
$ cd /scratch/nikos
# make some changes in README file
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
#
modified: README
#
no changes added to commit (use "git add" and/or "git commit -a")
git commit command can be used to commit the changes to commit the README
file changes in nikos local repository.
$ git commit m more changes in README file README
git status will now report that there are no uncommitted changes:
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
If nikos wants to push the changes in the shared repository, git push command
should be used:
$ git push origin master
If new files are needed to be added in the repository, the git add command should
be used prior to the git commit command:
$
$
$
$
touch newFile
# create a new file
git add newFile
# add the new file in the local repo
git commit m new file newFile commited # commit the new file in the local repo
git push origin master
# push the change in the shared repo
$ git diff
Reverting commits
In an unfortunate case that some commit should be reverted, git revert commit can
be used:
Conclusion
This document described a very limited set of capabilities that git has. An
interested user can go through [1] for more git capabilities and use cases (such as
branching, staging, stashing).
References
[1].
[2].
[3].