Project

General

Profile

Git

Git is a distributed version control system. You can use it independently, even without network access, then "push" your changes up to our main repository.

You can also browse the repository in Redmine using the "Repository" tab. (Should be above as you read this.)

Learning git

Git "thinks about" version control very differently than most other source control systems, such as Subversion or even Mercurial. The Git Reference is a good reference written in tutorial style, or perhaps it's a good tutorial that can be used as a reference. It's a quick read (10~15 min), and well worth it.

Special notes on using git on uboonedaq01

You must unset the environment variable `GIT_DIR` before using git.

 unset GIT_DIR

The variable `GIT_DIR` has special meaning for git. Unfortunately, the "setup" system from `/uboone/ups/setup` sets it. The simplest thing to do is simply to unset it.

Some practical examples

Below are a few specific examples of how to do things with our repository.

Cloning the main repository

Read/write access to the main repository is controlled through your Fermilab Kerberos key. Use the "git clone" command to obtain your own copy of the repository.

$ kinit
Password for you@FNAL.GOV:

$ git clone ssh://p-uboonedaq@cdcvs.fnal.gov/cvs/projects/uboonedaq/

You now have your own copy of the repository.

Making changes and committing changesets

As you work on your files, use "commit" to make a new snapshot of where you are, but first you must build up a list of changes to commit using "add". (N.B. Even modifications to existing files need to be "added"!)

Example:

$ mkdir git-fnal-instructions/                  
$ emacs git-fnal-instructions/initialize-repos  
$ git add git-fnal-instructions
$ git commit -m "Add a new hopefully helpful directory of files of git instructions." 
 2 files changed, 13 insertions(+), 0 deletions(-)
 create mode 100644 git-fnal-instructions/initialize-repos
 create mode 100644 git-fnal-instructions/initialize-repos~

Note that "add"ing a previously untracked directory will add all files in the directory, recursively. The above example added a file we didn't want. You can remove files with git rm.

Example:

$ git rm git-fnal-instructions/initialize-repos~
rm 'git-fnal-instructions/initialize-repos~'
$ git commit -m "remove crufty file" git-fnal-instructions/initialize-repos~

Other things worth knowing:
  • It is possible to check the changeset before committing (git status) and to "reset" the changeset before the commit if you don't like what you see (git reset).
  • There is a -a option to git commit that lets you skip the "add" step for files already being tracked. You still have to "add" new files to the changeset explicitly.
  • You can also explicitly list on the git commit command line every file whose changes you want to commit, in which case the "add" list is ignored.
  • See the The Git Reference for details.

Pushing your updates up to the main repository

$ git push ssh://p-uboonedaq@cdcvs.fnal.gov/cvs/projects/uboonedaq/

Warning: No xauth data; using fake authentication data for X11 forwarding.
Counting objects: 18, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (13/13), 31.33 KiB, done.
Total 13 (delta 4), reused 0 (delta 0)
To ssh://p-uboonedaq@cdcvs.fnal.gov/cvs/projects/uboonedaq/
   12f9f99..714f5c4  master -> master
Other things worth knowing:
  • If you made your local repo using clone, you can omit specifying the destination for the push, and it will default to the main repo.
  • You can organize your work using "branches" on your local repo and push them to the master branch on the main repo.
  • See the The Git Reference for details.

Pulling other people's updates down from the main repository

$ git pull ssh://p-uboonedaq@cdcvs.fnal.gov/cvs/projects/uboonedaq/ master
Warning: No xauth data; using fake authentication data for X11 forwarding.
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From ssh://cdcvs.fnal.gov/cvs/projects/uboonedaq
 * branch            master     -> FETCH_HEAD
Updating 714f5c4..760bc1a
Fast-forward
 git-fnal-instructions/add-dir-file |   48 ++++++++++++++++++++++++++++++++++-
 1 files changed, 46 insertions(+), 2 deletions(-)
Other things worth knowing:
  • If you made your local repo using clone, you can omit specifying the remote repo location, and it will default to the main repo.
  • The pull command is really a combination of two git commands named fetch and merge. If you want to look at the changes before merging them into your local copy, you can do fetch first, use diff in various ways, and then merge when ready.
  • If you need to abort an ongoing merge for any reason (e.g. conflicts that you don't want to immediately resolve), you can run:
    git merge --abort
    
  • See the The Git Reference for details.

Pulling other people's updates down from their copy of the repository!

Check how, with git, you can grab someone else's stuff by adding their directory as a remote repository. Then one defines a new branch (-b) and checks out from the new remote into it.

git remote add wk /home/wketchum/development/uboonedaq/
git checkout -b MRT_ElectronicsTest wk/MRT_ElectronicsTest

An extended example

Below is an extended example of getting a copy of the repository for the first time, adding a file in a new directory, committing, and pushing the change up to the master, performed on uboonedaq01

Please note: this example is provided for reference, without explanation. Please also read the above notes, or better yet the more informative, almost-as-short Git Reference. This is important to understand which steps you need to do all the time and which you don't. (E.g., you shouldn't keep cloning the repository, you should use `git pull` to update it once you have the clone.)

[gahs@uboonedaq01 ~]$ unset GIT_DIR

[gahs@uboonedaq01 ~]$ kinit gahs@FNAL.GOV
Password for gahs@FNAL.GOV:

[gahs@uboonedaq01 ~]$ git clone ssh://p-uboonedaq@cdcvs.fnal.gov/cvs/projects/uboonedaq/
Cloning into uboonedaq...
remote: Counting objects: 636, done.
remote: Compressing objects: 100% (395/395), done.
remote: Total 636 (delta 285), reused 422 (delta 201)
Receiving objects: 100% (636/636), 7.16 MiB | 158 KiB/s, done.
Resolving deltas: 100% (285/285), done.

[gahs@uboonedaq01 ~]$ cd uboonedaq/EPICS

[gahs@uboonedaq01 EPICS]$ mkdir apps/

[gahs@uboonedaq01 EPICS]$ ls

apps  README  teststand

[gahs@uboonedaq01 EPICS]$ mkdir apps/rc

[gahs@uboonedaq01 EPICS]$ cat > apps/rc/README
This directory is for run control EPICS apps for the uboone daq.

[gahs@uboonedaq01 EPICS]$ git add apps/rc

[gahs@uboonedaq01 EPICS]$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   apps/rc/README
#

[gahs@uboonedaq01 EPICS]$ git commit -m 'Add new directory for daq run control and monitor.'
[master 5a2aa8d] Add new directory for daq run control and monitor.
 Committer: Glenn Horton-Smith <gahs@uboonedaq01.fnal.gov>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name" 
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 EPICS/apps/rc/README

[gahs@uboonedaq01 EPICS]$ git push
Counting objects: 8, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 545 bytes, done.
Total 6 (delta 1), reused 0 (delta 0)
To ssh://p-uboonedaq@cdcvs.fnal.gov/cvs/projects/uboonedaq/
   376b935..5a2aa8d  master -> master

Other references

  • The Git Reference
    • This is a reference written in tutorial style, or perhaps it's a good tutorial that can be used as a reference.
    • You can read through "The Git Reference" in 10~15 minutes, and you will find it time well spent!
  • Everyday GIT With 20 Commands Or So
    • This is another reference, somewhat less well-organized for our purposes, but with more details, including details of git features that we don't anticipate needing (such as making patches for e-mailing, for example).