Your DevOps study space

Real explanations. Videos with tests. Fresh exams every time. Keep the streak alive and watch the XP stack up.

Rebase, stash & cherry-pick · Git Docs · StackwisePlanDevOps Rebase, stash & cherry-pick · Git Docs · StackwiseCodePython Rebase, stash & cherry-pick · Git Docs · StackwiseBuildDocker Rebase, stash & cherry-pick · Git Docs · StackwiseTestDevOps Rebase, stash & cherry-pick · Git Docs · StackwiseReleaseGit Rebase, stash & cherry-pick · Git Docs · StackwiseDeployKubernetes Rebase, stash & cherry-pick · Git Docs · StackwiseOperateLinux Rebase, stash & cherry-pick · Git Docs · StackwiseMonitorDevOps

Pick a topic

Eight tracks, each with docs, a cheat sheet, videos and tests.

How it works

One loop, repeated until it sticks.

Jump back in

Picked up from where you left off.

Free forever

Your DevOps journey starts with one click.

Sign in with Google or GitHub to open every chapter, video, test and challenge. Your progress is saved wherever you learn.

Rebase, stash & cherry-pick

Earlier chapters mentioned rebase, stash and reflog in a line each. This one goes deeper: how rebase rewrites history, cleaning up commits before a pull request, handling conflicts mid-rebase, juggling several stashes, copying a single commit between branches, and using the reflog to get out of almost any mess.

Rebase vs merge

You branched feature off main and made commits A, B, C; meanwhile main got F and G. git rebase main replays your commits one by one on top of G:

mergeABECDMa merge commit joins both linesrebaseABEC'D'one straight lineC', D' are new copies
Same end result in your files, different history. Rebase rewrites the feature commits, so only rebase branches nobody else has pulled.
before:
          A---B---C   feature
         /
    D---E---F---G     main

after git rebase main:
                  A'--B'--C'   feature
                 /
    D---E---F---G              main

A', B', C' contain the same changes but are new commits with new hashes, because their parent changed. History becomes a straight line, and merging into main is a fast-forward. Merge never rewrites anything but adds merge commits; rebase gives clean, linear history but rewrites commits. Many teams rebase their own branch to keep it current, then merge (or squash-merge) the pull request.

$ git switch feature/login
$ git fetch origin
$ git rebase origin/main
Successfully rebased and updated refs/heads/feature/login.
$ git push --force-with-lease     # the branch was pushed before, and its history changed

A normal push is now rejected because the remote still has the old commits. --force-with-lease overwrites only if nobody else pushed since your last fetch; plain --force would silently delete their work. git pull --rebase (or git config --global pull.rebase true) makes pulls rebase instead of merge.

Golden rule: never rebase commits others have based work on, like main or a shared branch. Their copies keep the old commits, and the next pull brings duplicates and confusing conflicts. Rebasing your own PR branch is fine as long as nobody else commits to it.

Interactive rebase: clean up before review

$ git rebase -i HEAD~4        # the last 4 commits
# or: git rebase -i main      # everything on this branch since it left main

Git opens a to-do list, oldest first. Change the command word on each line, then save and close:

pick 1a2b3c4 Add login form
pick 5d6e7f8 fix typo
pick 9a0b1c2 WIP
pick 3d4e5f6 Add password validaton

# edited to:
pick 1a2b3c4 Add login form
fixup 5d6e7f8 fix typo
fixup 9a0b1c2 WIP
reword 3d4e5f6 Add password validaton
  • pick: keep as is. reword: keep, but edit the message (fixing "validaton").
  • squash: melt into the commit above and edit the combined message. fixup: same, but discard this commit's message.
  • edit: stop here to change the content (git commit --amend, then git rebase --continue). drop or deleting the line: remove the commit.

Four messy commits become two clean ones; reordering lines reorders commits. Shortcut: commit a fix with git commit --fixup=1a2b3c4, and git rebase -i --autosquash main later puts it in place, already marked fixup.

Conflicts during a rebase

$ git rebase main
CONFLICT (content): Merge conflict in app.py
error: could not apply 6f700cc... Add login form
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
  1. Fix the conflict markers in the file, exactly as for a merge conflict.
  2. git add app.py. Don't run git commit: rebase commits for you.
  3. git rebase --continue. The next commit may conflict too; repeat until "Successfully rebased".

git rebase --abort puts everything back as before you started, and is always safe. --skip drops the conflicting commit. git status shows where you are.

During a rebase, "ours" and "theirs" are swapped compared with a merge: ours is the branch you're rebasing onto (main), theirs is your commit being replayed. Remember this with git checkout --ours/--theirs or VS Code's "Accept Current / Incoming".

Stash in depth

The stash is a stack: the newest entry is stash@{0}. Name your entries:

$ git stash push -m "half-done navbar"      # tracked changes, staged and unstaged
$ git stash push -u -m "with new files"     # -u also takes untracked files
$ git stash push -m "just css" -- style.css # only some paths
$ git stash list
stash@{0}: On feature/nav: just css
stash@{1}: On feature/nav: with new files
stash@{2}: On feature/nav: half-done navbar

$ git stash show -p stash@{2}     # the diff inside an entry
$ git stash apply stash@{2}       # apply, keep it in the list
$ git stash pop                   # apply stash@{0} and remove it
$ git stash drop stash@{1}        # delete one entry
$ git stash branch fix-nav stash@{2}   # new branch from where you stashed, changes applied
  • If pop hits a conflict, the entry is not dropped: resolve, then git stash drop yourself.
  • Without -u, new files aren't stashed and follow you to the other branch.
  • Stashes are local and never pushed. For anything long-lived, commit to a WIP branch instead.

Cherry-pick: copy one commit

Classic case: a bug fix landed on main, and release/1.4 needs it without everything else from main.

$ git switch release/1.4
$ git cherry-pick -x 9f1c2ab     # -x adds "(cherry picked from commit 9f1c2ab...)" to the message
$ git cherry-pick 4e5d6c7 9f1c2ab   # several, in that order
$ git cherry-pick A..B              # commits after A, up to and including B
$ git cherry-pick A^..B             # the same range including A

The copy gets a new hash. Conflicts work like in a rebase: fix, git add, git cherry-pick --continue (or --abort). If you're cherry-picking many commits, you probably want a merge or rebase instead.

The reflog: your undo history

Every time HEAD moves (commit, checkout, reset, rebase), Git logs it. Commits no branch points to are still reachable there. After an accidental git reset --hard HEAD~2:

$ git reflog
6ee1bf6 (HEAD -> feature/login) HEAD@{0}: reset: moving to HEAD~2
8634d90 HEAD@{1}: commit: Add password validation
6f700cc HEAD@{2}: commit: Add login form
$ git reset --hard 8634d90      # jump back to before the reset
$ git branch rescue 8634d90     # or: keep things as they are and save the commit on a branch
  • Undo a rebase you just finished: git reset --hard ORIG_HEAD (Git saves the old tip there before rebases, merges and resets).
  • Recover a deleted branch: find its last commit in the reflog, then git branch name <hash>.
  • The reflog is local and entries expire (by default 90 days, or 30 for commits no longer on any branch). It can't bring back changes that were never committed or stashed.

Common problems

  • "Updates were rejected" after rebasing: expected. git push --force-with-lease on your own branch, never on main.
  • Someone rebased a shared branch: with no local work on it, git fetch then git reset --hard origin/<branch>.
  • Stuck "in the middle of a rebase": git status explains; git rebase --abort gets you out.
  • Squashed the wrong commits: git reset --hard ORIG_HEAD and try again.

Questions

Pick an answer. Get it wrong and you can try again right away, no waiting. 10 questions per topic - pick a filter below, then use Recreate questions for a fresh set on that topic.

Fresh questions every time

Exam

A mixed test across the whole site, shuffled so you never know which topic comes next. When you submit, every mistake comes with the reason and a jump to the exact moment in the video that explains it.

30 questions 6 topics 20 minute limit Up to 70 XP
1–4 answer · ←→ move
History

Essay

0 / 200-250 words
Sample answer
History
0:00 / 0:00
Not started

on YouTube
Subscribe

Topic progress

Activity

Achievements

Settings

Your profile and your account.

Profile details

* Required. Saved in this browser until you sign in.

Letters, numbers, dots, dashes and underscores.
0 / 160

Account

Checking…

App

Install Stackwise on your phone or computer. It opens in its own window from your home screen, and the Docs and cheat sheets you've opened keep working without internet.

Only admins can see this

Dashboard

Sign-ups, activity, messages and reviews in one place.

Prove it

Certificates

Pass a topic's test and get a certificate with its own public page you can share or add to LinkedIn. Each test is 10 questions drawn at random and graded on the server; you need 8 right, you have 15 minutes, and you get one try per topic a day.

From first command to production

Linux for DevOps

A path through Linux the way DevOps engineers use it: ten stages, every command explained with its flags, examples, real output and mistakes, the combinations engineers chain together, and incidents worked through step by step. Practise everything in a safe lab folder.

Before the interview

Interview prep

Questions that come up in real DevOps interviews, with the kind of answer that lands. Say yours out loud first, then compare. Each one links to the chapter that goes deeper.

    Private to you

    My notes

    Everything you wrote down while watching and reading, in one place. Saved to your account, never shown to anyone.