Difference between revisions of "Git"

From WikiROMS
Jump to navigationJump to search
Line 2: Line 2:
ROMS source code is distributed using both [https://git-scm.com Git] and [https://subversion.apache.org Subversion](SVN). The Git repository includes the full history of changes to the ROMS source code. Details on using Subversion can be found [[Subversion|here]]. There are command line and GUI Git clients available for nearly every operating system and a list of popular clients can be found [https://git-scm.com/downloads/guis here]. This page will help you get started with downloading ROMS with Git.
ROMS source code is distributed using both [https://git-scm.com Git] and [https://subversion.apache.org Subversion](SVN). The Git repository includes the full history of changes to the ROMS source code. Details on using Subversion can be found [[Subversion|here]]. There are command line and GUI Git clients available for nearly every operating system and a list of popular clients can be found [https://git-scm.com/downloads/guis here]. This page will help you get started with downloading ROMS with Git.


==Git Overview==
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. All the ROMS/TOMS files are stored in a Git repository on '''www.myroms.org''' with access controlled by requiring authentication with the same ROMS Username/Password combination assigned to registered users of the ROMS Forum.


This Git repository is the official version of the code which only the developers are allowed to change. Users should download the ROMS code to their local machines using a '''git client'''. Don't attempt to use a regular web browser to browse or download files from the Git repository - there are much better tools for interacting with the code repository. See the notes below under the heading '''View the Repository'''.
{{note}}'''Note:''' For instructions using the deprecated and soon to be discontinued myroms.org git repository, click [[Talk:Git|here]].  


We strongly recommend users always check out the current ''master'' version since this has the most recent updates and bug fixes. The ''tags'' are kept largely as a historical record of stable releases at the conclusion of major code upgrades.


If you are making changes of your own, keep them in a separate branch, leaving the ''master'' branch to track changes from the source. Git makes it ''so'' much easier to manage your own modifications than svn for those of us without write permission on the repository.
==Git Overview==
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. All the ROMS/TOMS files are stored in a Git repository on '''github.com'''.


Below is a general description of how Git works. Please look at the [https://git-scm.com/book/en/v2 Pro Git] book for more detailed information. We have not yet tried any GUI clients but may add brief how-tos for the most popular GUIs at a later date.
This Git repository is the official version of the code which only the developers are allowed to change. Users should download the ROMS code to their local machines using a '''git client'''. Don't attempt to use a regular web browser to browse or download files from the Git repository - there are much better tools for interacting with the code repository.


==Saving ROMS Login Credentials==
We strongly recommend users always check out the current ''develop'' version since this has the most recent updates and bug fixes. The ''tags'' are kept largely as a historical record of stable releases at the conclusion of major code upgrades.
To avoid having to type your ROMS password many times while executing the steps in the [[#Downloading ROMS|Downloading ROMS]] section below, we suggest you setup a git credential manager.


If you are making changes of your own, keep them in a separate branch, leaving the ''develop'' branch to track changes from the source. Git makes it ''so'' much easier to manage your own modifications than svn for those of us without write permission on the repository.


{{note}}'''NOTE:''' If you have already setup a credential manager for other git repositories you should be able to add an entry for myroms following the documentation for the credential manager you are using.
Below is a general description of how Git works. Please look at the [https://git-scm.com/book/en/v2 Pro Git] book for more detailed information. We have not yet tried any GUI clients but may add brief how-tos for the most popular GUIs at a later date.


==Configuring GIT==


There are a few different options for storing your ROMS login credentials in order to avoid having to type your username and password for every command. See [https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage here] for more details. The simplest way to save your credentials is to use the built-in git-credential-store option. This option is very similar to the default way older Subversion clients store credentials so keep in mind that both your username and password will be stored without encryption in plain text. To use this method, execute the following:
Before downloading any of '''ROMS''' repositories, ensure that your '''~/.gitconfig''' has the appropriate '''git-lfs''' configuration for correctly downloading some '''''roms_test''''' input and observation NetCDF files. Otherwise, the '''Test Cases''' requiring input NetCDF files will fail. The '''Git LFS''' is a command line extension and specification for managing large files with '''Git'''. A sample of the configuration file looks like this:<div class="box">more ~/.gitconf<br /><br />  [User]<br />        name = GivenName MiddleName FamilyName<br />        email = your@email<br />  [credential]<br />        helper = cache --timeout=7200<br />        helper = store --file ~/.my-credentials<br />  [filter "lfs"]<br />        clean = git-lfs clean -- %f<br />        smudge = git-lfs smudge -- %f<br />        process = git-lfs filter-process<br />        required = true</div>


    > <span class="red">git config --global credential.helper 'store --file ~/.my-credentials'</span>
Alternatively, you may execute '''git lfs pull''' at your location of this repository to download a viable version of the '''Git LFS''' files from the remote repository in '''GitHub'''. Also, to automatically add the '''LFS''' filter to your existing '''~/.gitconfig''', you could use '''git lfs install''' from anywhere in your computer directories.


This will create a plain text file that only the file owner (you) has permission to access.
==Downloading ROMS==
{{warning}}'''WARNING:''' It is strongly suggested that you clone the ROMS source code using the same operating system you wish to compile and run ROMS on. If you download the code on a Windows machine and wish to run it on a non-Windows machine you will need convert the line endings with a utility like <span class="red">dos2unix</span> or <span class="red">recode</span>. Even with these utilities you may still have problems compiling ROMS.




===Saving Login Credentials Securely on Mac OS===
In order download source code from a git repository, '''git client''' software must be installed on your local machine. Most Linux distributions come with git, so shell commands may be used without installing additional software. The general form of git commands is:
If you are working on Mac OS there is a simple option for securely storing you credentials using the OS X Keychain. Simply execute:
 
    > <span class="red">git config --global credential.helper osxkeychain</span>
 
A window may pop up asking for your system's password to allow the credentials to be stored in your Keychain.


    <span class="red">git</span> action <repository>


===Saving Login Credentials Securely on Linux===
To check-out the files from the ROMS repository '''develop''' (latest version), enter (notice https instead of http):
Saving your credentials securely on Linux is a bit more complex and requires extra utilities (GPG) and configuration. This processes is adapted from [https://stackoverflow.com/questions/5343068/is-there-a-way-to-cache-github-credentials-for-pushing-commits/18362082#18362082 here] and requires Git version '''1.8.3''' or higher and GNU Privacy Guard (GnuPG or GPG). If you already use GPG and have a trusted key already you can skip the first step.


    > <span class="red">git clone <nowiki>https://github.com/myroms/roms.git</nowiki> MyDir</span>


*Create a GPG key:<div class="box">> <span class="red">gpg --gen-key</span><br />gpg (GnuPG) 2.0.22; Copyright (C) 2013 Free Software Foundation, Inc.<br />This is free software: you are free to change and redistribute it.<br />There is NO WARRANTY, to the extent permitted by law.<br /><br />Please select what kind of key you want:<br />  (1) RSA and RSA (default)<br />  (2) DSA and Elgamal<br />  (3) DSA (sign only)<br />  (4) RSA (sign only)<br />Your selection? <span class="red">1</span><br />RSA keys may be between 1024 and 4096 bits long.<br />What keysize do you want? (2048) <span class="red">4096</span><br />Requested keysize is 4096 bits<br />Please specify how long the key should be valid.<br />        0 = key does not expire<br />      <n>  = key expires in n days<br />      <n>w = key expires in n weeks<br />      <n>m = key expires in n months<br />      <n>y = key expires in n years<br />Key is valid for? (0) <span class="red">0</span><br />Key does not expire at all<br />Is this correct? (y/N) <span class="red">y</span><br /><br />GnuPG needs to construct a user ID to identify your key.<br /><br />Real name: <span class="red">Joe Roms</span><br />Email address: <span class="red">joe_roms@host.com</span><br />Comment: <span class="red">GPG Key</span><br />You selected this USER-ID:<br />    "Joe Roms <joe_roms@host.com>"<br /><br />Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? <span class="red">O</span><br /><br /><span class="blue">You need a Passphrase to protect your secret key.<br /><br /># You will be asked to type your passphrase twice</span><br /><br />We need to generate a lot of random bytes. It is a good idea to perform<br />some other action (type on the keyboard, move the mouse, utilize the<br />disks) during the prime generation; this gives the random number<br />generator a better chance to gain enough entropy.<br />gpg: key 33EA0E26 marked as ultimately trusted<br />public and secret key created and signed.<br /><br />gpg: checking the trustdb<br />gpg: 3 marginal(s) needed, 1 complete(s) needed, classic trust model<br />gpg: depth: 0  valid:   2  signed:  0  trust: 0-, 0q, 0n, 0m, 0f, 2u<br />pub  4096R/33EA0E26 2019-06-05<br />      Key fingerprint = 2CA2 904C A7DE CAEF 2266  70F6 1C74 375B 33EA 0E26<br />uid                  Joe Roms <joe_roms@host.com><br />sub  4096R/5A0EDB59 2019-06-05</div>
where '''MyDir''' is the destination directory on your local computer. It will be created if not found. If '''MyDir''' is omitted the code will be downloaded to a directory named '''roms'''. You only clone once because Git will keep track of the source, destination and a bunch of other information. For more detail on command line use and syntax, see the [https://git-scm.com/book/en/v2 Pro Git] book.


The idealized and realistic ROMS Test Cases and the Matlab processing software can be downloaded from:


*Download the <span class="limeGreen">git-credential-netrc</span> helper script from github and install it in a directory within your PATH. If there a multiple Git users on your system, you might want to have a system administrator place the script in <span class="purple">/usr/bin</span> or <span class="purple">/usr/local/bin</span> so all users will have access to it:<div class="box">> <span class="red"><nowiki>curl -o ~/bin/git-credential-netrc https://raw.githubusercontent.com/git/git/master/contrib/credential/netrc/git-credential-netrc.perl</nowiki></span></div>and give permissions to execute this script:<div class="box">> <span class="red"><nowiki>chmod 764 ~/bin/git-credential-netrc</nowiki></span></div>
    > <span class="red">git clone <nowiki>https://github.com/myroms/roms_test.git </nowiki></span>
    > <span class="red">git clone <nowiki>https://github.com/myroms/roms_matlab.git</nowiki></span>


We highly recommend that Users clone all the ROMS repositories from the same root directory in their computer and define the '''ROMS_ROOT_DIR''' variable in their computer shell login environment, specifying where the User cloned/downloaded the ROMS source code, Test Cases, and Matlab processing software. That is, use the value of pwd from the computer directory where you executed git clone https://github.com/myroms/roms.git


*Make a <span class="limeGreen">.netrc</span> file in your home directory in clear text using your favorite text editor:<div class="box">> <span class="red">cd ~</span><br />> <span class="red">vi .netrc</span></div>Enter the following text (replacing ''joe_roms'' and ''secret'' with your ROMS username and password) and save the file:<div class="box">machine www.myroms.org<br />login joe_roms<br />password secret<br />protocol https</div>You can add other blocks like the one above for other servers as well.
For bash shells:
    export ROMS_ROOT_DIR=MyDownlodLocationDirectory


For csh/tcsh shells:
    setenv ROMS_ROOT_DIR  MyDownlodLocationDirectory


*Encrypt that file using the email address you entered earlier while generating your GPG key:<div class="box">> <span class="red">gpg -e -r joe_roms@host.com .netrc</span></div>This will create a file named .netrc.gpg. You can now safely delete the <span class="limeGreen">.netrc</span> file (the unecrypted one).
The build scripts will use this environmental variable when compiling any of the ROMS Test Cases without the need to customize the location of the ROMS source code. Also, it is used for loading the path of Matlab scripts in the startup.m configuration file.


===Synchronizing Git and SVN revision information=== 


*Use the newly encrypted file for all git operations that require credentials:<div class="box">> <span class="red">git config --global credential.helper "netrc -f ~/.netrc.gpg -v"</span></div>or for just a specific respoitory:<div class="box">> <span class="red">cd /path/to/repository</span><br />> <span class="red">git config --local credential.helper "netrc -f ~/.netrc.gpg -v"</span></div>The first option will save the configuration to ~/.gitconfig while the second option will save to .git/config for the current git repository.
In order to synchronize the Git and Subversion repository revision information, we have created a Git filter that will insert the git hash of the last time a file was modified, similar to the Subversion '''''$Id$''''' keyword. In order for the filter to work, it has to be explicitly enabled by the user. After the git clone command from above completes change into <span class="limeGreen">MyDir</span> and execute the following:
 
 
From now on, any Git command using an HTTPS URL which requires authentication will decrypt that .netrc.gpg file and use the login/password associated to the server you are contacting. The first time, GPG will ask you for the passphrase of your GPG key, to decrypt the file. The other times, the gpg-agent launched automatically by the first GPG call will provide that passphrase for you.
 
 
{{note}}<span class="red">Note:</span> If your system's gpg program has a different name you will need to change the "git config" line accordingly. For example, on an UBUNTU machine the command would look something like this:
 
    > <span class="red">git config --global credential.helper "netrc -g gpg2 -f ~/.netrc.gpg -v"</span>
 
 
===Saving Login Credentials Securely on Windows===
We will add this once tested but you can follow the steps [https://stackoverflow.com/questions/5343068/is-there-a-way-to-cache-github-credentials-for-pushing-commits/18362082#18362082 here] if you would like to try it yourself.
 
==Downloading ROMS==
{{warning}}'''WARNING:''' It is strongly suggested that you clone the ROMS source code using the same operating system you wish to compile and run ROMS on. If you download the code on a Windows machine and wish to run it on a non-Windows machine you will need convert the line endings with a utility like <span class="red">dos2unix</span> or <span class="red">recode</span>. Even with these utilities you may still have problems compiling ROMS.
 
 
{{note}}'''NOTE:''' To avoid having to type your ROMS password many times while executing the steps below, we suggest you first set up a git credential manager as described in the [[#Saving ROMS Login Credentials|Saving ROMS Login Credentials]] section above. If you have already setup a credential manager for other git repositories you should be able to add an entry for myroms following the documentation for the credential manager you are using.
 
 
In order download source code from a git repository, '''git client''' software must be installed on your local machine. Most Linux distributions come with git, so shell commands may be used without installing additional software. The general form of git commands is:
 
    <span class="red">git</span> action <repository>
 
To check-out the files from the ROMS repository '''master''' (latest version), enter (notice https instead of http):
 
    > <span class="red">git clone <nowiki>https://www.myroms.org/git/src</nowiki> MyDir</span>
 
where '''MyDir''' is the destination directory on your local computer. It will be created if not found. If your want to avoid typing your '''username''' for all future code updates, change the command to:
 
    > <span class="red">git clone <nowiki>https://joe_roms@www.myroms.org/git/src</nowiki> MyDir</span>
 
You only clone once because Git will keep track of the source, destination and a bunch of other information. For more detail on command line use and syntax, see the [https://git-scm.com/book/en/v2 Pro Git] book.
 
In order to synchronize the Git and Subversion repository revision information, we have created a Git filter that will insert the git hash of the last time a file was modified, similar to the Subversion $Id$ keyword. In order for the filter to work, it has to be explicitly enabled by the user. After the git clone command from above completes change into <span class="limeGreen">MyDir</span> and execute the following:


     > <span class="red">git config filter.id.smudge ".git_filters/id.smudge %f"</span>
     > <span class="red">git config filter.id.smudge ".git_filters/id.smudge %f"</span>
Line 120: Line 88:


Git will remember where you checked out from before and see if a newer revision exists. If so, it will download and apply all the relevant changes.
Git will remember where you checked out from before and see if a newer revision exists. If so, it will download and apply all the relevant changes.
==Using GUI Git Clients==
{{warning}}'''WARNING:''' It is strongly suggested that you checkout the ROMS source code using the same operating system you wish to compile and run ROMS on. If you download the code on a Windows machine and wish to run it on a non-Windows machine you will need convert the line endings with a utility like <span class="red">dos2unix</span> or <span class="red">recode</span>. Even with these utilities you may still have problems compiling ROMS.
Once we have some experience with some GUI Git clients, we will add to this section.
===View the Repository===
The easiest way to view a repository is to simply look at it with [http://trac.edgewall.org/ Trac] in a web browser. Enter the URL:
  [https://www.myroms.org/projects/git-src/login https://www.myroms.org/projects/git-src/login]
and log in with your ROMS credentials. Once logged in, click the '''Browse Source''' tab near the top of the page. This is also a good way to see individual files in the repository without actually downloading them.


==Managing Your Own Modifications==
==Managing Your Own Modifications==
This assumes that you have a fresh clone of the myroms repository on the '''master''' branch. You want to keep '''master''' as a pure copy of the source version and keep your own changes in say the '''arctic''' branch. Start by creating a branch and switching to it:
This assumes that you have a fresh clone of the myroms repository on the '''develop'' branch. You want to keep '''develop''' as a pure copy of the source version and keep your own changes in say the '''arctic''' branch. Start by creating a branch and switching to it:


  > <span class="red">git branch arctic<br /></span>> <span class="red">git checkout arctic</span>
  > <span class="red">git branch arctic<br /></span>> <span class="red">git checkout arctic</span>
Line 147: Line 101:


===Getting the Updates===
===Getting the Updates===
It is easy to fetch and merge the updates. Start by making sure your directory has been cleanly checked in with <span class="red">git status</span>.  Then you can update your '''master''' branch:
It is easy to fetch and merge the updates. Start by making sure your directory has been cleanly checked in with <span class="red">git status</span>.  Then you can update your '''develop''' branch:


  > <span class="red">git checkout master</span><br />> <span class="red">git pull</span>
  > <span class="red">git checkout develop</span><br />> <span class="red">git pull</span>


Then bring the changes into your '''arctic''' branch:
Then bring the changes into your '''arctic''' branch:


  > <span class="red">git checkout arctic</span><br />> <span class="red">git merge master</span>
  > <span class="red">git checkout arctic</span><br />> <span class="red">git merge develop</span>


This will bring in everything that changed since your last <span class="red">git pull</span>, so you might find it easier to keep on top of things by doing this often, not putting it off for years. You can also bring in changes one at a time with <span class="red">git cherry-pick</span>. Again, check the Pro Git book for much more information about all of these operations.
This will bring in everything that changed since your last <span class="red">git pull</span>, so you might find it easier to keep on top of things by doing this often, not putting it off for years. You can also bring in changes one at a time with <span class="red">git cherry-pick</span>. Again, check the Pro Git book for much more information about all of these operations.


Note that this will save your '''arctic''' branch locally, under the .git directory. You can back this up as you would any other important files you have. The gitish way to back it up is to the cloud, say on github. In the best of all possible open source projects, the '''master''' would be on github too, and you'd simply fork from it there. If you want to try this out, fork from Mark Hadfield's copy of the myroms source at [https://github.com/hadfieldnz/roms-trunk-mgh].
Note that this will save your '''arctic''' branch locally, under the .git directory. You can back this up as you would any other important files you have.
 
==Useful Git Commands==
{| border="1" cellspacing="0" cellpadding="5" align="center"
|'''Command'''
|'''Description'''
|-
| '''git add''' <_FileName_>
| Add a file to the repository staging area
|-
| '''git branch'''
| List all local branches (the asterisk denotes the current branch)
|-
| '''git branch -a'''
| List all local and remote branches
|-
| '''git branch -d''' <_BranchName_>
| Delete a local branch
|-
| '''git branch -D''' <_BranchName_>
| Delete a local branch forcefully
|-
| '''git branch -m''' <_OldName_> <_NewName_>
| Rename a local branch
|-
| '''git checkout -b''' <_BranchName_>
| Create a new local branch and switch to it
|-
| '''git checkout''' <_BranchName_>
| Switch to an existing local or remote branch
|-
| '''git clone''' <_RepositoryURL_>
| Clone a public repository
|-
| '''git commit -am''' "<_Message_>"
| Commit changes to all files
|-
| '''git commit -am''' "<_Message_>" '''-m''' "<_MessageURL_>"
| Commit changes to all files with two message lines
|-
| '''git commit --amend -m''' "<_NewMessage_>"
| Amend previous commit message
|-
| '''git diff'''
| Show all changes between HEAD and working branch
|-
| '''git diff''' <_FileName_>
| Show changes for a specific file between HEAD and working branch
|-
| '''git difftool -d''' <_BranchName1_> <_BranchName2_>
| Compare the difference between two branches with '''`KDIFF3`'''
|-
| '''git fetch'''
| Retrieve new work done by other people
|-
| '''git log'''
| View repository changes
|-
| '''git log --oneline'''
| Show the list of commits in one-line format
|-
| '''git log --summary'''
| View repository detailed changes
|-
| '''git merge --no-ff --no-commit''' <_BranchName_>
| Merge a branch into the active branch
|-
| '''git pull'''
| Update local repository or branch to the newest origin commit
|-
| '''git push origin --delete''' <_BranchName_>
| Delete a remote branch
|-
| '''git push -u origin''' <_BranchName_>
| Push changes to the remote repository (and remember the branch)
|-
| '''git reset --hard HEAD~1'''
| Undo last commit
|-
| '''git revert''' <_CommitID_>
| Revert commit changes
|-
| '''git status'''
| Check/display changes to the repository or particular branch
|-
| '''git tag'''
| List all tags
|}
 
 
==Complicated Commands==
 
If a branch is renamed in a repository on GitHub, the local clone on a computer needs to updated:<div class="box">git branch -m OldName NewName<br />git fetch origin<br />git branch -u origin/NewName NewName<br />git remote set-head origin -a</div>
 
How to merge changes in the '''feature/name1''' branch into the '''feature/name2''' branch:<div class="box">git checkout feature/name1<br />git pull<br /><br />git checkout feature/name2<br />git pull<br />git merge --no-ff --no-commit feature/name1<br />git commit -am "Merging feature/name1 into feature/name2" -m "MessageURL"<br />git difftool -d feature/name1 feature/name2<br />git push -u origin feature/name2</div>

Revision as of 21:34, 23 August 2023

Git

ROMS source code is distributed using both Git and Subversion(SVN). The Git repository includes the full history of changes to the ROMS source code. Details on using Subversion can be found here. There are command line and GUI Git clients available for nearly every operating system and a list of popular clients can be found here. This page will help you get started with downloading ROMS with Git.


NoteNote: For instructions using the deprecated and soon to be discontinued myroms.org git repository, click here.


Git Overview

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. All the ROMS/TOMS files are stored in a Git repository on github.com.

This Git repository is the official version of the code which only the developers are allowed to change. Users should download the ROMS code to their local machines using a git client. Don't attempt to use a regular web browser to browse or download files from the Git repository - there are much better tools for interacting with the code repository.

We strongly recommend users always check out the current develop version since this has the most recent updates and bug fixes. The tags are kept largely as a historical record of stable releases at the conclusion of major code upgrades.

If you are making changes of your own, keep them in a separate branch, leaving the develop branch to track changes from the source. Git makes it so much easier to manage your own modifications than svn for those of us without write permission on the repository.

Below is a general description of how Git works. Please look at the Pro Git book for more detailed information. We have not yet tried any GUI clients but may add brief how-tos for the most popular GUIs at a later date.

Configuring GIT

Before downloading any of ROMS repositories, ensure that your ~/.gitconfig has the appropriate git-lfs configuration for correctly downloading some roms_test input and observation NetCDF files. Otherwise, the Test Cases requiring input NetCDF files will fail. The Git LFS is a command line extension and specification for managing large files with Git. A sample of the configuration file looks like this:

more ~/.gitconf

[User]
name = GivenName MiddleName FamilyName
email = your@email
[credential]
helper = cache --timeout=7200
helper = store --file ~/.my-credentials
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true

Alternatively, you may execute git lfs pull at your location of this repository to download a viable version of the Git LFS files from the remote repository in GitHub. Also, to automatically add the LFS filter to your existing ~/.gitconfig, you could use git lfs install from anywhere in your computer directories.

Downloading ROMS

WarningWARNING: It is strongly suggested that you clone the ROMS source code using the same operating system you wish to compile and run ROMS on. If you download the code on a Windows machine and wish to run it on a non-Windows machine you will need convert the line endings with a utility like dos2unix or recode. Even with these utilities you may still have problems compiling ROMS.


In order download source code from a git repository, git client software must be installed on your local machine. Most Linux distributions come with git, so shell commands may be used without installing additional software. The general form of git commands is:

   git action <repository>

To check-out the files from the ROMS repository develop (latest version), enter (notice https instead of http):

   > git clone https://github.com/myroms/roms.git MyDir

where MyDir is the destination directory on your local computer. It will be created if not found. If MyDir is omitted the code will be downloaded to a directory named roms. You only clone once because Git will keep track of the source, destination and a bunch of other information. For more detail on command line use and syntax, see the Pro Git book.

The idealized and realistic ROMS Test Cases and the Matlab processing software can be downloaded from:

   > git clone https://github.com/myroms/roms_test.git 
   > git clone https://github.com/myroms/roms_matlab.git

We highly recommend that Users clone all the ROMS repositories from the same root directory in their computer and define the ROMS_ROOT_DIR variable in their computer shell login environment, specifying where the User cloned/downloaded the ROMS source code, Test Cases, and Matlab processing software. That is, use the value of pwd from the computer directory where you executed git clone https://github.com/myroms/roms.git

For bash shells:

   export ROMS_ROOT_DIR=MyDownlodLocationDirectory

For csh/tcsh shells:

   setenv ROMS_ROOT_DIR  MyDownlodLocationDirectory

The build scripts will use this environmental variable when compiling any of the ROMS Test Cases without the need to customize the location of the ROMS source code. Also, it is used for loading the path of Matlab scripts in the startup.m configuration file.

Synchronizing Git and SVN revision information

In order to synchronize the Git and Subversion repository revision information, we have created a Git filter that will insert the git hash of the last time a file was modified, similar to the Subversion $Id$ keyword. In order for the filter to work, it has to be explicitly enabled by the user. After the git clone command from above completes change into MyDir and execute the following:

   > git config filter.id.smudge ".git_filters/id.smudge %f"
   > git config filter.id.clean ".git_filters/id.clean %f"

In order to get the Git Id hashes to fill in, you will need to force the smudge filter to run on the source code you have already downloaded. This takes several minutes but only needs to be done once. For bash shells execute:

   > rm .git/index
   > git checkout HEAD -- "$(git rev-parse --show-toplevel)"

For csh/tcsh shells execute:

   > rm .git/index
   > git checkout HEAD -- "`git rev-parse --show-toplevel`"

If you look at the top of any ROMS source file downloaded from the git repository, you will see both the Git commit hash for the last time that file was modified and the corresponding SVN revision properties. For example, the first few lines of ROMS/Modules/mod_ncparam.F look like this:

#include "cppdefs.h"
MODULE mod_ncparam
!
!git $Id: b42658ab652647fca27d50af4afa15c3401fe544 $
!svn $Id: mod_ncparam.F 968 2019-06-17 16:02:48Z arango $
!================================================== Hernan G. Arango ===
! Copyright (c) 2002-2019 The ROMS/TOMS Group  !
! Licensed under a MIT/X style license  !
! See License_ROMS.txt  !
!=======================================================================

You can then use the 40 character (hexidecimal) Git hash to show more information about that code update:

> git show --name-only b42658ab652647fca27d50af4afa15c3401fe544

While you are getting your configuration in order, you also want to tell git who you are:

  > git config --global user.name "your name"
> git config --global user.email "your@email"

This is important if you plan to ever commit your own modifications.

Several GUI front-ends to Git exist, allowing the user to have visual prompts to help them manage their files and credentials.

Updates

Now and again, you might feel the urge to get up to speed with the latest changes that have been made to the ROMS repository. When that happens, simply go to the directory that was "MyDir" above and type:

   > git pull

Git will remember where you checked out from before and see if a newer revision exists. If so, it will download and apply all the relevant changes.

Managing Your Own Modifications

This assumes that you have a fresh clone of the myroms repository on the develop branch. You want to keep develop' as a pure copy of the source version and keep your own changes in say the arctic branch. Start by creating a branch and switching to it:

> git branch arctic
> git checkout arctic

Now you can make whatever modifications you like (and test them out). To see what changed, you can use git status and git diff. To save your changes, do a:

> git commit -a

Though if you add new files you will have to git add them first.

Getting the Updates

It is easy to fetch and merge the updates. Start by making sure your directory has been cleanly checked in with git status. Then you can update your develop branch:

> git checkout develop
> git pull

Then bring the changes into your arctic branch:

> git checkout arctic
> git merge develop

This will bring in everything that changed since your last git pull, so you might find it easier to keep on top of things by doing this often, not putting it off for years. You can also bring in changes one at a time with git cherry-pick. Again, check the Pro Git book for much more information about all of these operations.

Note that this will save your arctic branch locally, under the .git directory. You can back this up as you would any other important files you have.

Useful Git Commands

Command Description
git add <_FileName_> Add a file to the repository staging area
git branch List all local branches (the asterisk denotes the current branch)
git branch -a List all local and remote branches
git branch -d <_BranchName_> Delete a local branch
git branch -D <_BranchName_> Delete a local branch forcefully
git branch -m <_OldName_> <_NewName_> Rename a local branch
git checkout -b <_BranchName_> Create a new local branch and switch to it
git checkout <_BranchName_> Switch to an existing local or remote branch
git clone <_RepositoryURL_> Clone a public repository
git commit -am "<_Message_>" Commit changes to all files
git commit -am "<_Message_>" -m "<_MessageURL_>" Commit changes to all files with two message lines
git commit --amend -m "<_NewMessage_>" Amend previous commit message
git diff Show all changes between HEAD and working branch
git diff <_FileName_> Show changes for a specific file between HEAD and working branch
git difftool -d <_BranchName1_> <_BranchName2_> Compare the difference between two branches with `KDIFF3`
git fetch Retrieve new work done by other people
git log View repository changes
git log --oneline Show the list of commits in one-line format
git log --summary View repository detailed changes
git merge --no-ff --no-commit <_BranchName_> Merge a branch into the active branch
git pull Update local repository or branch to the newest origin commit
git push origin --delete <_BranchName_> Delete a remote branch
git push -u origin <_BranchName_> Push changes to the remote repository (and remember the branch)
git reset --hard HEAD~1 Undo last commit
git revert <_CommitID_> Revert commit changes
git status Check/display changes to the repository or particular branch
git tag List all tags


Complicated Commands

If a branch is renamed in a repository on GitHub, the local clone on a computer needs to updated:

git branch -m OldName NewName
git fetch origin
git branch -u origin/NewName NewName
git remote set-head origin -a

How to merge changes in the feature/name1 branch into the feature/name2 branch:

git checkout feature/name1
git pull

git checkout feature/name2
git pull
git merge --no-ff --no-commit feature/name1
git commit -am "Merging feature/name1 into feature/name2" -m "MessageURL"
git difftool -d feature/name1 feature/name2
git push -u origin feature/name2