Stash & Tags Questions with Answers

6 practice questions on Stash & Tags (Git & DevOps) with answers and step-by-step solutions. Try 6 samples below, then practise all 6 free in the AptiNest app.

Sample questions

Question 1Easy

How do you include untracked files in a stash?

  1. git stash --all-tracked
  2. git stash -u
  3. git stash push --new
  4. It is always included

Answer: B. git stash -u

Explanation

By default stash ignores untracked files; -u adds them (-a also ignored files).

Step-by-step solution

  1. Default stash is tracked only.
  2. -u adds untracked.
  3. -a adds ignored too.

Why the other options are wrong

  • A. Invalid option.
  • C. Invalid option.
  • D. They are not included by default.

Question 2Easy

How do you list all stashes?

  1. git stash show-all
  2. git stashes
  3. git log --stash
  4. git stash list

Answer: D. git stash list

Explanation

git stash list shows stash@{0}, stash@{1}, newest first.

Step-by-step solution

  1. Stashes form a stack.
  2. List shows them newest first.
  3. Apply a specific one via stash@{n}.

Why the other options are wrong

  • A. No such option.
  • B. No such command.
  • C. Not an option.

Question 3Easy

Which command creates an annotated tag v1.0 with a message?

  1. git tag -a v1.0 -m "Release 1.0"
  2. git tag v1.0 -commit
  3. git branch -t v1.0
  4. git label v1.0

Answer: A. git tag -a v1.0 -m "Release 1.0"

Explanation

Annotated tags are full objects with author, date and message. A lightweight tag is just a ref.

Step-by-step solution

  1. -a makes it annotated.
  2. -m sets the message.
  3. Push with git push origin v1.0.

Why the other options are wrong

  • B. Invalid option.
  • C. Branches are not tags.
  • D. No such command.

Question 4Easy

What does git stash do?

  1. Pushes the uncommitted changes to the remote repository as a branch
  2. Deletes uncommitted changes
  3. Saves uncommitted tracked changes on a stack and cleans the working tree
  4. Creates a new branch

Answer: C. Saves uncommitted tracked changes on a stack and cleans the working tree

Explanation

Stash temporarily shelves work so you can switch tasks. Restore it with pop or apply.

Step-by-step solution

  1. Edits are saved.
  2. Tree matches HEAD.
  3. git stash pop brings them back.

Why the other options are wrong

  • A. Stash is local only.
  • B. Changes are saved, not deleted.
  • D. No branch is created.

Question 5Medium

Difference between git stash pop and git stash apply?

  1. pop keeps the entry in the list and apply removes it afterwards
  2. They are identical
  3. pop applies and drops the stash entry; apply keeps it
  4. pop pushes to remote

Answer: C. pop applies and drops the stash entry; apply keeps it

Explanation

Apply is useful to reuse the same stash on several branches.

Step-by-step solution

  1. Both re-apply the changes.
  2. pop removes the entry.
  3. apply keeps it in the list.

Why the other options are wrong

  • A. It is the other way around.
  • B. Pop removes the entry.
  • D. Stash is local.

Question 6Medium

What does git describe typically output for a commit 3 commits after the annotated tag v2.0?

  1. Only the word v2.0, whatever the number of later commits is
  2. The tag message
  3. The parent hash
  4. A name like v2.0-3-gabc1234 (tag, commits since, short hash)

Answer: D. A name like v2.0-3-gabc1234 (tag, commits since, short hash)

Explanation

It describes a commit relative to the nearest reachable tag, handy for version strings.

Step-by-step solution

  1. Find nearest tag.
  2. Count commits since it.
  3. Append g plus the short hash.

Why the other options are wrong

  • A. Plain tag only on the tagged commit.
  • B. Messages are shown by git show.
  • C. Not a parent hash.

Practise all 6 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Git & DevOps topics · All topics