GIT · Branches · 10 min
Replay your work after a hotfix
Put a local documentation change on top of the updated main.
Not completedYour task
Rebase feature/docs onto main without a merge commit. Keep both the main hotfix and your documentation.
What you’re aiming for
- main is an ancestor of feature/docs.
- hotfix.txt and docs.txt are present.
- The three-commit history has no merge 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.
mkdir opsrung-git-rebase-onto-main && cd opsrung-git-rebase-onto-main
Run these setup commands in that folder:
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 feature/docs printf '%s\n' 'Explain the release.' > docs.txt git add -- docs.txt git commit -m 'Write documentation' git switch main printf '%s\n' 'Validate incoming IDs.' > hotfix.txt git add -- hotfix.txt git commit -m 'Apply urgent hotfix' git switch feature/docs
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.
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
Switching branches does not move commits.
Hint 2
Rebase replays your local commits on a new base.
Hint 3
While on feature/docs, run git rebase main.
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.
git status git log --oneline --graph --all -12
What you should see
- main is an ancestor of feature/docs.
- hotfix.txt and docs.txt are present.
- The three-commit history has no merge 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
git rebase main
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.