Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Chapter 5Name in the course: Rebasing

Keep a clean history with rebase

Rebase moves your commits on top of another branch, as if you had started your work there. The history becomes one straight line — easier to read and review. Interactive rebase also lets you clean up commits before you share them.

  • 5 Lessons
  • 2 Commands

$ run as a normal user# run as root (or with sudo)

5.1

Rebase a branch on main

While you worked, main moved on. Rebase replays your commits on the new main.

git switch feature/web-network
git fetch origin
git rebase origin/main
git push --force-with-lease
before:   main  A---B---C
                 \
          feature D---E
 
after:    main  A---B---C
                         \
          feature         D'--E'

Remember

Rebase rewrites commits (new hashes D', E'). Never rebase commits other people already built on — only your own feature branch.

Commands in this lesson

5.2

Solve conflicts during a rebase

A rebase stops at each commit that conflicts. Fix it, then continue.

git status
vim main.tf
git add main.tf
git rebase --continue
git rebase --skip
git rebase --abort

5.3

Clean up commits interactively

git rebase -i opens a list of your commits. Change the word in front to squash, reword, reorder or drop commits — before you open the pull request.

git rebase -i origin/main
Editor during git rebase -i
pick 1a2b3c4 Add web subnet
fixup 5d6e7f8 typo
pick 9a8b7c6 Add NSG rules
reword 3c4d5e6 wip
drop 7f8e9d0 debug output
WordEffect
pickKeep the commit
rewordKeep, change the message
squashJoin with the commit above, edit the message
fixupJoin with the commit above, keep its message
dropRemove the commit

At work

Commit with git commit --fixup=HASH while you work, then git rebase -i --autosquash origin/main puts every fix in the right place.

Commands in this lesson

5.4

Choose merge or rebase

Both bring changes together. Teams pick a style and stick to it.

MergeRebase
HistoryTrue, with merge commitsStraight line
Safe on shared branchesYesNo (rewrites)
ConflictsOncePossibly per commit
Common useMerging a PR into mainUpdating your own feature branch

5.5

Pick single commits

git cherry-pick copies one commit from another branch — for example a hot fix from main into a release branch.

git switch release/1.2
git cherry-pick 3f2a9c1
git cherry-pick -x 3f2a9c1

-x adds "cherry picked from commit …" to the message, so the link is clear.

Commands in this lesson

All commands in this chapter