Git

The Carob project is developed using the “git” versioning software. This greatly facilitates collaborative work and making incremental improvements because all changes made are tracked. A git project is called a “repo” (repository) and the “main” Carob repo is hosted on github .

To contribute to the Carob repo (and to other github based projects) you need to understand a few concepts and commands that we introduce here.

The first thing you need to do is create an account on github if you do not have one (other projects using git may use another platform such as bitbucket for their git projects ). Once you have an account, you can fork the Carob repo to your account. A fork is a copy of a git repo that you can make changes to, while also getting any updates that are made to the main repo.

fork

To fork the Carob repo, navigate to its github site, click on the Fork button and choose your personal account as the target.

fork1

The forked repo will then be added to your github account. The text below the repository name shows that the repo is a fork.

fork2

Now you can clone (make a copy of) your fork to your computer so that you can make changes to it. You can make any change you like, as it does not affect the main repo (original project). However, if you want to contribute back to the main repo you should keep these changes to a minimum. There is no need to worry too much about making mistakes, as you can simply delete your clone or fork and create a new one if things went wrong.

After you make changes you need to add and/or commit your work and then push these from your computer to your Carob fork on github. You can do these things with different tools and we provide instructions for the command line (which we recommend) and RStudio (you can also use GitHub Desktop).

branches

Each pull request (PR) must cover only one dataset (one script at a time). Pull requests that combine multiple scripts covering multiple datasets are not allowed because they are much harder to review and merge cleanly. Exceptions can be made if, for example, a trivial change is needed in multiple files. When in doubt, you can open a github “issue” to discuss this.

If you work directly on your fork’s main branch and open a PR, any new commits you push to main are automatically added to that same open PR. That means you cannot submit a second script until the first PR is merged.

The clean solution is to create a separate branch for each script. Keep your main branch untouched and synced with carob-data/carob, and branch off main whenever you start a new dataset. That way you can have several independent PRs open at the same time — one script per branch.

Here is the recommended workflow on the command line (you can also create and switch branches using the branch menu in RStudio or GitHub Desktop):

  1. Start from an up-to-date ``main`` branch. First sync your fork on GitHub with carob-data/carob (click Sync fork on your fork’s GitHub page), then update your local copy:

git checkout main
git pull
  1. Create a new branch named after the dataset or script you are working on:

git checkout -b doi_10.7910_DVN_XXXXXX
  1. Write and test your script, then stage and commit only that script on the new branch:

git status
git add scripts/agronomy/doi_10.7910_DVN_XXXXXX.R
git commit -m "new agronomy script doi:10.7910/DVN/XXXXXX"
  1. Push the branch to your fork on GitHub:

git push -u origin doi_10.7910_DVN_XXXXXX
  1. Open a pull request on GitHub from doi_10.7910_DVN_XXXXXX to carob-data/carob:main (see pull-request below).

  2. Start another script in parallel. Without waiting for the first PR to be merged, switch back to main, pull any updates, and create a new branch for the next dataset:

git checkout main
git pull
git checkout -b doi_10.7910_DVN_YYYYYY

If a reviewer requests changes on an open PR, switch back to that PR’s branch, commit the fix, and push — only that PR will be updated:

git checkout doi_10.7910_DVN_XXXXXX
git add scripts/agronomy/doi_10.7910_DVN_XXXXXX.R
git commit -m "fix units in doi:10.7910/DVN/XXXXXX"
git push

After a PR has been merged into carob-data/carob, sync your fork’s main branch and you can delete the finished branch locally (git branch -d doi_10.7910_DVN_XXXXXX) and on GitHub.

working with drafts in _todo

Many datasets already have a draft script in scripts/_todo/<group>/ (see the to-do list). Checking, fixing, and completing one of these drafts is a great way to contribute.

When you finish a draft, it must be moved from scripts/_todo/<group>/ to scripts/<group>/. Do not move and edit the file in the same commit. If you move a file and make substantial edits before committing, Git may lose track of the rename and show your PR as a deleted file plus an unrelated new file, hiding the diff of your changes and breaking the file’s change history.

Instead, always work on a dedicated branch for that script and keep the edits and the move in two separate commits. The cleanest approach is to finish and commit your edits inside scripts/_todo/ first, and then move the file with git mv in a second commit:

  1. Create a branch from an up-to-date main branch:

git checkout main
git pull
git checkout -b doi_10.7910_DVN_XXXXXX
  1. Review, edit, and test the draft script right inside scripts/_todo/<group>/. When you are satisfied with your changes, stage and commit them:

git add scripts/_todo/agronomy/doi_10.7910_DVN_XXXXXX.R
git commit -m "review and complete agronomy draft doi:10.7910/DVN/XXXXXX"
  1. Move the completed script into scripts/<group>/ with git mv (do not delete and copy it manually) and commit the move by itself:

git mv scripts/_todo/agronomy/doi_10.7910_DVN_XXXXXX.R scripts/agronomy/doi_10.7910_DVN_XXXXXX.R
git commit -m "move agronomy script doi:10.7910/DVN/XXXXXX from _todo"
  1. Push the branch and open your pull request:

git push -u origin doi_10.7910_DVN_XXXXXX

You can also do the two commits in the reverse order — run git mv and commit the move first, then make your edits and commit them in a second commit. Either order preserves the full change history and lets reviewers see exactly what changed from the original draft.

Avoid whitespace-only changes: Many scripts in scripts/_todo/ use tabs for indentation, whereas RStudio converts tabs into spaces by default, which can make nearly every line appear modified in your diff. Spaces are fine in code you write, as long as existing tabs are not converted to spaces (or vice versa). Open the repository via carob.Rproj in RStudio, and uncheck Insert spaces for tab in RStudio’s global options (see RStudio editor settings or R coding style).

pull-request

If you have pushed a branch with changes to your fork of the Carob repo that you would like to contribute to the project, you can open a “pull request” (often abbreviated to “PR”). Remember that each PR must contain only one script (one dataset) — do not bundle multiple scripts for different datasets into a single PR.

Before opening a PR, make sure that your branch was created from an up-to-date main branch synced with the main repo at carob-data/carob. It is imperative to ensure that the only difference between your branch and the main repo is the change (e.g., one new or edited script) that you want to contribute. Syncing regularly avoids “conflicts” in which you changed a file that was also changed by someone else.

After you push a branch to your fork, GitHub will normally display a Compare & pull request banner at the top of your repository page. You can also select your branch on GitHub and click the Contribute button:

pull-request-1

Write a message in the box describing your contribution, and click on create a pull request.

pull-request-2

See this document for a more fundamental description of making pull-requests, including the command line approach.