Guide to git for FMS Users and Developers
This document provides a brief description of git and some specifics on how it is implemented for FMS. A similar guide for CVS is also available. For more details on git see the homepage, which contains a user reference and a full copy of the Pro Git book a list of tutorials and other help materials. Graphical user interfaces (GUI) are available with git (git-gui, gitk) for both committing and local views of the repository logs. The git repositories for GFDL are located on the lab’s gitlab instance.
Git is a source code management (SCM) system. It maintains a record of all changes made to a project in a group of files called the repository. The official master git repository is located on GFDL’s gitlab server. The fms user, a computer system user on the GFDL systems, acts as the super-user for all the git repositories.
As most users in the GFDL community are familiar with the Concurrent Version System (CVS), the information provided in this guide will leverage on the concepts of CVS. However, it is important to understand the differences in git and CVS.
Git for CVS users
The largest difference between git and CVS is the repository layout. In CVS files for a particular group of code (project) is managed with a set of CVS modules. A single CVS repository can have multiple modules. With git, the repository is more like the CVS module.
Another difference is git does not support the checkout of a single file from the repository. Git considers the repository as a single entity, and will grab every file during the clone/checkout.
Lastly, git is a distributed system. Thus, each working directory is a full copy of the repository. When the repository is “downloaded”, every file and every revision is “cloned” into the working directory. This has the slight disadvantage in that modifications to the working directory are not mirrored back to the “official” master repository. Pushing back changes is a separate step.
Tags and branches have similar meanings in git as they do in CVS.
Branch Creation Summary for FMS Developers
The FMS developers have been assigned to a group on the gitlab server. If you have a GFDL account and wish to join the FMS developers group, please submit a help desk ticket help@gfdl.noaa.gov
When checking in modifications to code, it is important to start from the correct version of the code. For example, if you have modified tikal code, you should start from the “tikal” tag in your working repository. If your change is to be included into the next software cycle, you should start with the current testing branch code. If not, your modifications may not be accepted. Note that the testing branch is used to test updates that will be included in the next city/patch release and should not be used for production runs.
Using git status and git log before and after each command below will help inform you how the repository changes after each command. Click on the individual git commands for more details on the specific commands. Also running git <command> --help should display the on-line manual page.
To check in modified files on a new branch: |
|
git checkout -b user/$user/<branch_name> git add files git commit git push origin user/$user/<branch_name> |
|
To check in modified/new files on your existing branch: |
|
git status git add files git commit git push user/$user/<branch_name> |
|
To remove a file from the repository on a branch: |
|
git rm files git commit git push user/$user/<branch_name> |
|
To add a revision tag to a file or directory: |
|
git tag user/$user/<tag_name> git push user/$user/<tag_name> |
|
To remove a revision tag from a file or directory: |
|
git tag -d user/$user/<tag_name> git push origin :refs/tags/<user/$user/<tag_name> |
|
General Information and Formatting of git Commands:
git -help | Display a brief help message listing the git options, and a list of the most commonly used commands. |
git <command> -h | List a brief help message on the usage of <command>. For example, cvs clone -h will print a help message for the clone git command. |
git <command> --help | Display the man page for the <command>. Note: The same man page can be displayed by running man git-<command>. For example, git add -h and man git-add will both display the same man page. |
git <command> [<files>] | This is the general format for git commands. Note: Some git commands will require a list of files (e.g. git add <files>) while other will work on the repository (e.g. git branch). There is also a subset of commands that can either work on the repository, or a list of files (e.g. git checkout [<files>]). |
Commands which do not modify the repository:
The following commands are for acquiring code from the FMS repository and inquiring as to the state of your local code compared with the state of the repository.
Clone Command:git clone [-b <branch>] <repo> |
|
Example: git clone -b siena_201309 git@gitlab.gfdl.noaa.gov:fms/sharedClone the repository located at git@gitlab.gfdl.noaa.gov:fms/shared and checkout the “siena_201309” named tag/branch. |
|
Description:Clones the full repository located at <repo>, and optionally checkout a particular branch/tag. Please note, the git clone is more like CVS checkout in that collects revision information from a remote repository. Git, unlike CVS, will always clone a full repository – all files, all revision. Like CVS, if a particular branch/tag are not listed on the command line, then the HEAD (trunk in CVS) is left in the working directory. | FMS Considerations:When asking for a particular tag, a warning stating that the working directory is in a “detached HEAD” state. This is simply a warning to let you know that if changes are committed, then they will not be associated with any named branch. It is suggested that all modification be placed on a branch. Thus run then command git checkout -b <branch_name> prior to committing any changes. |
Commands which do modify the repository:
The following commands allow developers add files and modifications to the repository
Branch Command:git branch [-l] [-f] <branch> [<start-point>] git branch [-a|-r] [--merged|--no-merged] |
|
Example: git branch user/sdu/my_new_branchCreate a new branch user/sdu/my_new_branch starting from the current working HEAD. | |
Description:The branch command creates new branches, or lists the local/remote branches. When creating a branch with the command git branch [-l] [-f] <branch> [<start-point>], the branch is created but the working directory’s current branch does not change. Use the git checkout <branch> to change to the newly created branch. Local branches can be listed by simply running git branch without the optional branch name. Remote branch can be listed by adding either the -a (to list all branches, local and remote) or -r (to list only remote branches) options. | FMS Considerations:For branches in the FMS repository, the branch name should follow the pattern user/$user/<branch_name> |
Tag Command:git tag <tag_name> [<commit>] |
|
Example: git tag user/sdu/my_new_tag masterCreate a new tag user/sdu/my_new_branch on the latest commit on the master branch. | |
Description:Create a new tag from in the repository. | FMS Considerations:For tags in the FMS repository, the tag name should follow the pattern user/$user/<tag_name>.Also note, the git tag command is different than the cvs tag command in that you can only create tags with the git version. To create a branch, use the branch or |
Commit Command:git commit [-a] [-m <message>] |
|
Example: git commit -m 'A commit message'Commit the changes in the index using a commit message of “A commit message” | |
Description: | FMS Considerations:None. |
Add Command:git add [<filepattern>] |
|
Example: git add foo/barAdd file foo/bar as either a file to track, or add the file modifications to the index to be included in the next commit. | |
Description:Add work in two different ways. The first is to add files as tracked in git. This is similar to how add was used in CVS. The other method is to add file modifications to the index. The index is a staging area. File modifications in the index will be included in the next call to git commit. | FMS Considerations:None. |