Basic Information


About the Repositories

There are two CARMA repositories in GitHub:

This is the repository, or repo, for the CARMA model core source code, used in CESM, specifically in CAM or WACCM.
Changes to the main code are pushed to this repo which presently has one main (default) branch and, and may, at times, include other experimental branches.

This is the repository for the stand-alone regression tests of the CARMA model core source code, and the self-generated HTML documentation. It has a single default branch, main, and points to the CARMA_base repo for the source code in the source/base directory. 

For more information on the CARMA stand-alone regression tests see:



Getting Help on Git

The Linux man page for Git presents detailed information about Git. To invoke, type:

man git

or

git help git

You can access an abbreviated Git help which lists common Git commands by typing:

git help


The following three commands will return detailed, Linux man page-type help on any Git command, as well as available options to the command:

git <command> --help,

git help <command>

or

man git <command>


A tutorial introduction to Git can be accessed by typing the following at the command line:

git help tutorial 



Some Basic Git Commands

Some basic Git commands and a few options in no particular order:



Some Online Git References

Some online references on the basics of using Git:

 Provides links to Git tutorials and references, and information about setting up your Git environment. This wiki is written specifically for the CAM Github repository,
but the instructions can be generalized to other repositories.

 “[M]eant to be a quick reference for learning and remembering the most important and commonly used Git commands”

“[F]eatures the most important and commonly used Git commands for easy reference.”

Lists basic Git commands with basic information on each and examples on their use.



Making and Saving Revisions to the CARMA GitHub Repositories


If you plan to submit new code or code modifications to the CARMA or CARMA_base repositories, and you don't already have a fork of the repository
you wish to modify, you will need to make one. 
Please note that you can have only a single fork of any one remote repository at a time.

Modifications should never made in the CARMA Github repositories, nor in your remote fork. Instead, you will need to clone a local copy of your remote
repository fork in an account on a Linux machine such as cheyenne. Modifications will be made in your clone (your local repository), then pushed up to
your fork.

Following are the steps to make a fork of a remote repository such as the CARMA_base or CARMA stand-alone, then create a local clone of your fork in
which to make and test modifications to the code.

Make a Fork

To make a fork of a remote repository:



You will be asked where to make the fork; select your GitHub account if more than one choice is offered. Your new fork will include all the branches that are
part of the parent repository.



Create a Clone

You will need to clone your fork to create a local copy of the repository on your Linux account; it is this local clone (local repo) where you will
make and test your changes.


​​git clone --recursive https://github.com/<userid>/CARMA.git <clone name>


where  <userid> is your GitHub user ID and <clone name> is the name you wish to give your clone as well as the name of the directory into which
your fork is cloned. 
Note that <clone name> is optional, but if you do not provide a name, your clone and directory will be named CARMA.


cd <clone

git remote add ESCOMP https://github.com/ESCOMP/CARMA.git


git fetch ESCOMP



Create a New Branch in Your Clone

git branch <branch> ESCOMP/main


Where <branch> is the name you give your new branch. The second argument, ESCOMP/main is where on the repository “tree” your branch begins.


git checkout <branch>


You’re now ready to make modifications in your branch on your local repository.



Modifying the Files in Your Clone

Make modifications and/or additions to the files in your clone, save and test your changes. Repeat this process until you’re satisfied with the changes you’ve
made.
You’re now ready to stage and commit the changes to your repository. When your modifications have been committed to your clone you can push them
up to your fork.



Save Your Changes to Your Local Repository

Saving your changes to your local repository involves three steps:


git status

An example of output from a git status command:

On branch kappa_dev

Your branch is up to date with 'myCARMAfork/kappa_dev'.

Changes not staged for commit:

  (use "git add <file>..." to update what will be committed)

  (use "git restore <file>..." to discard changes in working directory)

modified:   source/base (new commits)

Untracked files:

  (use "git add <file>..." to include in what will be committed)

build/

doc/f90doc/

run/

tests/bench/carma_kappawetrtest.txt 

no changes added to commit (use "git add" and/or "git commit -a")


In this example you can see that the new file carma_kappawetrtest.txt  in directory  tests/bench/ is not yet tracked.
Note that directories build/, doc/f90doc/ and run/are also untracked, but these don't belong in the CARMA stand-alone
repository so they should not be staged (added) or committed to your clone.


git add <new_file(s)


Using the information in the “git status” example above you would type 

git add tests/bench/carma_kappawetrtest.txt

to stage the new file.


If you have more than one file to add you can type the file names sequentially on the same line; e.g.,

git add <new_file1> <new_file2> <new_file3> ...


Or you can add each one individually:

git add <new_file1>

git add <new_file2

git add <new_file3

etc, ...


If you want to stage everything you can do the following:

git add *


But be careful with this command: be sure that you want all of the files you’re about to add to be pushed to the remote repository.
In the example above you would find that you’ve added all of the files in the directories build/, doc/f90doc/ and run/.


git commit -m “<description of changes/reason for commit>”


where <description of changes/reason for commit> is a short commit message describing all the changes in this commit.


To enter a longer message, omit the m and the  <description of changes/reason for commit>

git commit 

Depending on how you’ve set up your Git environment, an editor window should open that allows you to enter a longer, more
detailed message than is possible using the first version above.


Another option that allows you to write a longer message, as well as to edit you message, is to create a text file <filename> in which
you put your commit comments, then use
the -F option:

git commit -F <filename>


Your changes have now been committed to your local repository; you are almost ready to  push those changes up to your remote fork.
Before pushing your changes back to your fork you will need to bring your local repository up-to-date  with the remote upstream repository.



Bringing Your Local Branch Up-to-date with the Remote Repository

If you will be updating your local branch frequently or working in this or other branches from your fork in the future adding a "shortcut" remote
for the CARMA repository may be advisable.

To add a remote called upstream to the CARMA repository, type:

git remote add upstream https://github.com/ESCOMP/CARMA


Now, rather than typing out

git fetch https://github.com/ESCOMP/CARMA


all that is needed for the git fetch command is:

git fetch upstream


git checkout <your branch>


 git merge ESCOMP/CARMA_base


Your working branch in your local repository is now up-to-date with the upstream remote repository.



Push Your Changes to Your Fork

To move your local changes up to the remote repository you will push them:

git push <origin> <branch>


where  <branch>  is the name you gave your branch and <origin>  is the name of the source repository; here, your personal fork.
The default name is ‘origin’, so, if you have not renamed it, you can type 

git push origin <branch>


You will be asked for your GitHub userid and password.


git branch 


You should see output similar to this:

* new_feature

  master


The branch you are working in is denoted by the asterisk. In this example, the branch in use is new_feature.



git push -u <origin> <branch>


For example,

git push -u <origin> new_feature


This will create a new branch in your fork named new_feature identical to the branch of the same name in your local repo. The -u option
will “add upstream (tracking) reference…” (from
git push –help.)

Note: You will be asked for your GitHub user ID when you issue the git push command.




Open a Pull Request (PR)

You must get approval for the changes you’ve pushed to your fork before they can be merged into the CARMA code. To do this, you will need
to open a pull request or PR.








Give your PR a title and write a short comment explaining the purpose of this pull request.
Click on the “gear”to the right of "Reviewers" in the upper right hand corner to select reviewers for your PR.

After you enter a title, the Create pull request button will become active; click it to create your pull request.
Or you may click on the pull down arrow on the right end of the button and choose Create draft pull request.






The icon in the upper left hand corner of the panel will turn green when all
 requested changes have been made and your pull request approved.