Skip to content

OSCAL Tips and Tricks

Michaela Iorga edited this page Feb 2, 2024 · 1 revision

OSCAL Tips and Tricks

Synchronizing Your Fork with Upstream

You do not have to a fork (in this context github.com/yourusername/OSCAL is a fork; github.com/usnistgov/OSCAL) and staff can create branches on the upstream repository. However, you may prefer to use your fork to prepare work before pushing to the upstream. If so, you may need to sync your develop and main branches from your fork with the upstream.

To follow this process there are important assumptions you make.

  1. The GitHub web interface has a sync branches feature for forks in our projects. This approach uses merge commits on the branches in the fork, and not 1:1 match of the branches. This strategy can lead to messier history history and potential conflicts later, we do not recommend doing this.
  2. Your fork is the origin remote, and the upstream usnistgov/OSCAL repo is upstream.
  3. You do not make any changes you want to save your develop or main branch in any circumstance. Following this guidance, they will be blown away.

To reset your fork's develop branch with the upstream develop, use the commands below.

$ git remote -v # If you results match below, you can skip the next few commands and skip to git fetch
origin      [email protected]:yourusername/OSCAL.git (fetch)
origin      [email protected]:yourusername/OSCAL.git (push)
upstream [email protected]:usnistgov/OSCAL.git (fetch)
upstream [email protected]:usnistgov/OSCAL.git (push)
$ git remote remove origin
$ git remote remove upstream # It may throw an error because it doesn't exist, this is to be safe.
$ git remote add upstream [email protected]:usnistgov/OSCAL.git
$ git remote add origin [email protected]:yourusername/OSCAL.git
$ git fetch --all # This is important or the next commands will reflect older "current" commits on the remotes, correct or incorrect.
$ git checkout --track origin/develop # first time
$ # Did you see the following error?
$ # 'fatal: A branch named 'develop' already exists.'
$ # If yes, you will do the command below after the first time.
$ git checkout develop # after first time
$ git reset --hard upstream/develop
$ git push origin develop -f

To reset your fork's main branch with the upstream main:

$ git remote -v # If you results match below, you can skip the next few commands and skip to git fetch
origin      [email protected]:yourusername/OSCAL.git (fetch)
origin      [email protected]:yourusername/OSCAL.git (push)
upstream    [email protected]:usnistgov/OSCAL.git (fetch)
upstream    [email protected]:usnistgov/OSCAL.git (push)
$ git remote remove origin
$ git remote remove upstream # It may throw an error because it doesn't exist, this is to be safe.
$ git remote add upstream [email protected]:usnistgov/OSCAL.git
$ git remote add origin [email protected]:yourusername/OSCAL.git
$ git fetch --all # This is important or the next commands will reflect older "current" commits on the remotes, correct or incorrect.
$ git checkout --track origin/main # first time
$ # Did you see the following error?
$ # 'fatal: A branch named 'develop' already exists.'
$ # If yes, you will do the command below after the first time.
$ git checkout main  # after first time
$ git reset --hard upstream/main
$ git push origin main -f

Pull Request Branch Management

If you are asked to make a pull request for an issue, you need to create a branch based off your target branch. Before you make a feature branch you likely need to make a rough sketch branch. The target may be the usnistgov/OSCAL develop branch, a feature- prefix branch, or main branch. You can approach this from 1 or 2 methods.

  1. Traditional Command Line Method with git
  2. GitHub Web Interface Method

Traditional Command Line Method with git

You need to first ensure you have selected the correct target branch for the PR. In this case, in the example below, I will assume develop, not main.

$ git clone [email protected]:usnistgov/OSCAL.git
$ pushd OSCAL
$ git remote -v # Ensure below origin has usnistgov in the URL, if not use the correct remote alias if not origin
origin  [email protected]:usnistgov/OSCAL.git (fetch)
origin  [email protected]:usnistgov/OSCAL.git (push)
$ git checkout --track origin/develop # first time
$ # or if you see an error that branch develop already exists
$ git checkout develop # after first time
$ git fetch --all # ensure if you have done the above days or weeks again
$ git reset --hard origin/develop # IMPORTANT: you will delete uncommitted work on your local develop, but you should not use this or main anyway
$ git checkout -b name-for-new-pr-branch-targeting-develop
$ git push origin HEAD # or the appropriate remote alias

GitHub Web Interface Method

You need to first ensure you have selected the correct target branch for the PR. In this case, in the example below, I will assume develop, not main.

  1. Open the relevant issue
  2. Open the create branch from issue menu on the lower right-hand side of the issue.

image

  1. Click the change branch source menu and choose the target develop branch and click the Create Branch button.

image

  1. Follow clone instructions accordingly.

Submodule Management

Updating the Metaschema submodule in a PR

Switching to a fork sub-module for a draft PR

  1. Open the OSCAL repository on your workstation.
  2. Checkout your new branch from the target branch (develop or main):
$ git remote -v # confirm origin is usnistgov/OSCAL
me      [email protected]:youruser/OSCAL.git (fetch)
me      [email protected]:youruser/OSCAL.git (push)
origin  [email protected]:usnistgov/OSCAL.git (fetch)
origin  [email protected]:usnistgov/OSCAL.git (push)
$ git fetch --all
$ git checkout --track origin/develop
$ git checkout -b new-pr-to-develop # create PR branch
$ git push me HEAD # push to your fork
$ git submodule update --init --recursive
$ cd build/metaschema/
$ git fetch --all
$ git remote -v # confirm origin is usnistgov/metaschema-xslt
me      [email protected]:youruser/metaschema-xslt.git (fetch)
me      [email protected]:youruser/metaschema-xslt.git (push)
origin  [email protected]:usnistgov/metaschema-xslt.git (fetch)
origin  [email protected]:usnistgov/metaschema-xslt.git (push)
$ git checkout --track me/metaschema-fork-updated
$ cd ..
$ git submodule set-url build/metaschema [email protected]:youruser/metaschema-xslt.git
$ git add .gitmodules build/metaschema
$ git commit -m "[WIP] Test metaschema-xslt sub-module change to test tooling to fix model issue."
Clone this wiki locally