Stash Work, Fix Bug, Restore and Update
IBM ☯️ Medium Git
Beginner Mode

Start your terminal to use beginner mode.

Scenario

Uncommitted changes on feature-ui prevent you from switching branches to fix a critical bug on main.

Task

Stash local changes to clean the working directory with message WIP: UI improvements. Switch to a new branch hotfix-auth to implement the fix, then merge it into main. Finally, rebase feature-ui against the updated main and restore your stashed changes.

Changes in hotfix-auth branch are below:

echo  "Fixing critical bug" >> src/auth.js

git commit -m "Fix critical authentication bug"

Example

Bash

# Before (Switch blocked)
error: Your local changes to the following files would be overwritten by checkout:
        src/ui.js
Please commit your changes or stash them before you switch branches.

# After (Updated and Restored)
$ git log --oneline -1 main
a1b2c3d Fix critical authentication bug
$ git status
On branch feature-ui
Changes not staged for commit:
  modified:   src/ui.js

Terminal requires a larger screen

Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.

Linux Terminal Environment

Write and execute your solution in the terminal below.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →