GIT · Advanced history · 10 min

Move only the fix to the release branch

Detach two useful commits from unrelated topic work.

Not completed

Your task

Rebase fix/runtime onto main while excluding the topic commit. Keep both fix files and release.txt; topic.txt must be absent.

What you’re aiming for

  • main is an ancestor of fix/runtime.
  • fix-a.txt and fix-b.txt are present, while topic.txt is absent.
  • The fix branch contains four commits.

1. Prepare your practice folder

Use Git 2.28 or newer. The setup commands below use a Bash-compatible shell: Git Bash on Windows, or Bash on Linux/macOS.

Create a new, empty folder for this exercise. If that name already exists, choose another new name. Continue only after you’re inside the new folder.

NEW PRACTICE FOLDER
mkdir opsrung-git-rebase-only-fix && cd opsrung-git-rebase-only-fix

Run these setup commands in that folder:

SETUP — RUN ONCE
git init --initial-branch=main
git config --local user.name 'Practice Learner'
git config --local user.email 'practice@example.invalid'
printf '%s\n' 'A disposable OpsRung practice repository.' > README.txt
git add -- README.txt
git commit -m 'Start practice'
git switch -c topic/experiment
printf '%s\n' 'Unrelated experiment.' > topic.txt
git add -- topic.txt
git commit -m 'Add experiment'
git tag topic-base
git switch -c fix/runtime
printf '%s\n' 'Validate input.' > fix-a.txt
git add -- fix-a.txt
git commit -m 'Fix validation'
printf '%s\n' 'Limit response data.' > fix-b.txt
git add -- fix-b.txt
git commit -m 'Fix response'
git switch main
printf '%s\n' 'Stable release.' > release.txt
git add -- release.txt
git commit -m 'Prepare release'
git switch fix/runtime
Only if your personal Git settings interfere

You can normally skip this. If a commit asks for a signing key, runs a custom hook, or changes line endings unexpectedly, these repository-local overrides keep this disposable exercise independent of those settings.

OPTIONAL REPOSITORY OVERRIDES
git config --local commit.gpgsign false
git config --local core.autocrlf false
git config --local core.hooksPath .git/practice-no-hooks

Retry the failed command afterward. These settings apply only inside this practice repository.

2. Try the task

Work toward the goal above. Start by inspecting the files or resources, then use a hint if you need one.

Hint 1

--onto separates the new base from the old range boundary.

Hint 2

The tag topic-base marks the unrelated change you must exclude.

Hint 3

Run git rebase --onto main topic-base fix/runtime.

3. Review your result

Use these commands to look at your result and compare it with the goals. The website does not run or verify them.

REVIEW IN YOUR TERMINAL
git status
git log --oneline --graph --all -12

What you should see

  • main is an ancestor of fix/runtime.
  • fix-a.txt and fix-b.txt are present, while topic.txt is absent.
  • The fix branch contains four commits.

If your result differs: Work only in this exercise’s repository. Compare the branch, files, and history with every goal before marking complete.

Compare with one possible solution
ONE POSSIBLE SOLUTION — BASH
git rebase --onto main topic-base fix/runtime

Other approaches are fine if you reach the same goal. Opening this solution does not mark the exercise complete.

Finished this exercise?

You decide when you’re done. Your choice is saved in this browser, and you can change it later.