Bird
Raised Fist0
Gitdevops~20 mins

Creating named stashes in Git - Practice Exercises

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Git Stash Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of creating a named stash?
You run the command git stash push -m "work in progress" in a repository with unstaged changes. What will git stash list show as the top entry?
Astash@{0}: WIP on main: work in progress
Bstash@{0}: On main: work in progress
Cstash@{0}: On main - work in progress
Dstash@{0}: WIP main work in progress
Attempts:
2 left
💡 Hint
The message format includes 'WIP on' followed by the branch name and the message.
💻 Command Output
intermediate
1:30remaining
What error occurs with invalid stash message syntax?
What error will occur if you run git stash push -m without providing a message?
Aerror: switch `m' requires a value
Bfatal: You must provide a message with -m
Cerror: missing message for stash
Dfatal: no stash message given
Attempts:
2 left
💡 Hint
Check the error message about missing value for the -m option.
🔀 Workflow
advanced
2:30remaining
Which command sequence correctly creates and applies a named stash?
You want to save your current changes with a name and then apply them back later. Which sequence of commands does this correctly?
Agit stash save "feature update" && git stash pop stash@{0}
Bgit stash push -m feature update && git stash pop stash@{0}
Cgit stash push -m "feature update" && git stash apply stash@{0}
Dgit stash push "feature update" && git stash apply stash@{1}
Attempts:
2 left
💡 Hint
Remember the correct syntax for naming a stash and applying it.
Troubleshoot
advanced
2:00remaining
Why does git stash push -m fail with 'unknown option' error?
You run git stash push -m "fix bug" but get an error: error: unknown option '-m'. What is the likely cause?
AYou must use double dashes before -m like --m
BYour git version is older and does not support the -m option for stash push
CThe message must be provided without quotes
DYou need to run git stash save instead of push
Attempts:
2 left
💡 Hint
Check your git version and its support for stash push options.
Best Practice
expert
3:00remaining
What is the best practice for naming stashes to avoid confusion in a team?
Which naming style for stash messages helps a team clearly understand the purpose of each stash?
A"temp"
B"WIP"
C"fix"
D"<branch-name>: <short description> - <date>"
Attempts:
2 left
💡 Hint
Think about clarity and useful information in the stash message.

Practice

(1/5)
1. What is the main benefit of creating a named stash in Git?
easy
A. It automatically commits your changes to the main branch.
B. It helps you remember what changes you saved by adding a message.
C. It deletes all your untracked files before saving changes.
D. It merges your changes directly into the remote repository.

Solution

  1. Step 1: Understand what a stash does

    A stash saves your current work temporarily without committing it.
  2. Step 2: Recognize the purpose of naming a stash

    Giving a stash a name or message helps you remember what changes it contains.
  3. Final Answer:

    It helps you remember what changes you saved by adding a message. -> Option B
  4. Quick Check:

    Named stash = clear message [OK]
Hint: Named stashes add messages to remember saved changes easily [OK]
Common Mistakes:
  • Thinking stash commits changes permanently
  • Confusing stash with branch creation
  • Assuming stash deletes files permanently
2. Which of the following is the modern correct command to create a named stash with the message "fix bug"?
easy
A. git stash save "fix bug"
B. git stash add -m "fix bug"
C. git stash create "fix bug"
D. git stash push -m "fix bug"

Solution

  1. Step 1: Recall the modern syntax for named stashes

    The correct command uses git stash push -m "message" to create a named stash.
  2. Step 2: Check each option for correctness

    git stash push -m "fix bug" matches the correct syntax exactly; others use outdated or invalid commands.
  3. Final Answer:

    git stash push -m "fix bug" -> Option D
  4. Quick Check:

    Named stash command = git stash push -m [OK]
Hint: Use 'git stash push -m "message"' for named stashes [OK]
Common Mistakes:
  • Using 'git stash save' which is deprecated
  • Using 'git stash create' which does not name stashes
  • Using 'git stash add' which is invalid
3. What will be the output of the command git stash list after running git stash push -m "update readme"?
medium
A. stash@{0}: WIP on main: update readme
B. Error: stash message not saved.
C. No stash entries found.
D. stash@{0}: On main: update readme

Solution

  1. Step 1: Understand what 'git stash push -m' does

    This command creates a stash with the message "update readme".
  2. Step 2: Check the format of 'git stash list' output

    Named stashes show as stash@{0}: WIP on main: update readme.
  3. Final Answer:

    stash@{0}: WIP on main: update readme -> Option A
  4. Quick Check:

    Named stash list shows WIP on branch: message [OK]
Hint: Named stash appears in list as 'WIP on branch: message' [OK]
Common Mistakes:
  • Thinking named stashes lack 'WIP on' prefix
  • Thinking stash list is empty after push
  • Assuming error when message is given
4. You tried to create a named stash with git stash push -m fix typo but got an error. What is the likely cause?
medium
A. The message must be enclosed in quotes.
B. The command 'git stash push' does not support messages.
C. You need to add '--message' instead of '-m'.
D. You must commit changes before stashing.

Solution

  1. Step 1: Identify the syntax error in the command

    The message contains spaces and must be enclosed in quotes to be treated as one argument.
  2. Step 2: Understand correct usage of message option

    Using -m "fix typo" is correct; missing quotes causes error.
  3. Final Answer:

    The message must be enclosed in quotes. -> Option A
  4. Quick Check:

    Message with spaces needs quotes [OK]
Hint: Always quote stash messages with spaces [OK]
Common Mistakes:
  • Omitting quotes around multi-word messages
  • Using wrong option like '--message'
  • Thinking stash requires committed changes
5. You have multiple stashes saved with names. How can you apply the stash named "feature update" without removing it from the stash list?
hard
A. git stash apply -m "feature update"
B. git stash pop -m "feature update"
C. git stash apply stash^{/feature update}
D. git stash apply feature update

Solution

  1. Step 1: Understand how to reference named stashes

    Named stashes can be referenced using stash^{/message} syntax to match the message.
  2. Step 2: Choose the correct command to apply without removing

    git stash apply applies without removing; pop removes. git stash apply stash^{/feature update} uses correct syntax.
  3. Final Answer:

    git stash apply stash^{/feature update} -> Option C
  4. Quick Check:

    Apply named stash with 'stash^{/message}' [OK]
Hint: Use 'stash^{/message}' to apply named stash without popping [OK]
Common Mistakes:
  • Using 'pop' which removes stash
  • Trying to use '-m' with apply
  • Passing message directly without stash^{/}