Skip to content

Rebasing from CBICA GaNDLF to mlcommons GaNDLF

Alexander Getka edited this page Oct 23, 2022 · 3 revisions

Why this is needed

When migrating to the mlcommons repo, we took the opportunity to clean up GaNDLF's git history to remove problematic LFS commits that were causing issues when mirroring.

As a result, there is a "new history" (without the LFS commits, in the new repo) and an "old history" (the actual history of GaNDLF's commits from the old repo).

Any changes based on the old history will cause issues with the new history (because the new history and old history are separate, git may either fail to compare them, preventing PRs, or try to merge them -- we do NOT want this.)

For new changes, you can just branch off of the mlcommons/GaNDLF master and all will be fine. However, for any changes that were in progress, you will need to rebase to the new history. Effectively this process snips off your changes from the top of the old history, and grafts them onto the new history. As part of this process, we will also check your local git configuration just to make sure we're pointing to the right place.

PLEASE NOTE: These instructions only apply if you are working on a fork of the GaNDLF repo. If you are working with mirror(s) or remotes with different fetch/push URLs, you will need to modify the git remote configuration to suit your situation.

Rebase instructions:

Checking configuration

Check origin (and possibly upstream) with:

git remote show origin

git remote show upstream

Most likely, "origin" is your fork, and "upstream" is either the primary GaNDLF repo or doesn't exist.

If "upstream" points to https://github.com/CBICA/GaNDLF.git, change it to https://github.com/mlcommons/GaNDLF.git with:

git remote set-url upstream https://github.com/mlcommons/GaNDLF.git

If upstream doesn't exist, then add it with:

git remote add upstream https://github.com/mlcommons/GaNDLF.git

The remote "origin" should point to your fork, e.g. https://github.com/AlexanderGetka-cbica/GaNDLF.git . If not, follow the same process:

git remote set-url origin https://github.com/{your-github-username-here}/GaNDLF.git

DOUBLE CHECK THAT YOUR REMOTES CONFIGURATION IS CORRECT. If your "origin" is https://github.com/CBICA/GaNDLF.git or https://github.com/mlcommons/GaNDLF.git (as it would be by cloning those directly), any pushes you do will go directly to the main repo. At best, this will fail with a permissions error, and at worst, it will overwrite/break the main repo. So don't do it.

Then to pull branch info from upstream:

git fetch upstream

Check the branches with:

git branch -v -a

You should see remotes/upstream/master in there, along with the latest commit listed on the mlcommons/GaNDLF repo. Please double-check this before continuing.

Updating your fork master

First, let's update our own main/master branch on our fork. We start by checking out the new correct master:

git checkout -b new-master upstream/master

Next, force-update your fork's master branch. Keep in mind this will overwrite it.

git push -f origin new-master:master

This will rewrite your master's history to be consistent with the new history, and ensure that you can pull new changes from mlcommons/GaNDLF. You can now just branch off origin/master for any future work.

You can delete the local new-master branch with:

git branch -d new-master

Updating your working branches

Now, you want to rebase any of your current working branches. This step is necessary if you have changes that are based on the old history, and want to push them to the new repo. You might notice this if your PR contains far more file changes/commits/conflicts than expected, or if github complains of no common history.

Check out the branch:

git checkout my-feature-branch

Create a backup in case things go wrong (make sure all your important work is saved/committed first!):

git checkout -b my-feature-branch-backup

Go back to the original branch:

git checkout my-feature-branch

MAKE SURE YOU ARE ON THIS BRANCH FOR ALL SUBSEQUENT STEPS. "reset" and "rebase" both operate on the CURRENT ACTIVE BRANCH.

Just in case, reset the current branch versus your backup. This will erase any in-progress changes that were not included in your backup.

git reset --hard my-feature-branch-backup

Now you can perform the rebase. This will graft the commits from your current working branch onto the new history.

git rebase upstream/master

Now push those changes to your fork's copy of the branch (with -f for force-push, necessary to rewrite history)

git push -f origin my-feature-branch

You're done now unless there's an error. If the fork doesn't already have a copy of that branch, you'll get an error about there not being an upstream for my-feature-branch. If so, you can create it with:

git push --set-upstream origin my-feature-branch

Note that you don't need -f/--force in this case, because you aren't overwriting anything on the remote -- you are simply creating a new branch on the remote from your local branch.

You can now create a pull request in the typical way, and only your relevant changes should show up.