WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Git · Basic · question 13 of 100

Can you explain the difference between ’git stash’ and ’git stash apply’?

📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

In Git, git stash and git stash apply are commands used to temporarily save changes in a Git repository. However, there are some important differences between the two commands.

git stash is used to save changes that are not ready to be committed, but you don’t want to lose them either. When you run the git stash command, Git will save your changes in a temporary storage area called the stash. The stash is like a stack, so you can stash changes multiple times, and each time you stash, the new stash becomes the top of the stack.

Here’s an example of how to use the git stash command:

    # Stash changes that are not ready to be committed
    git stash

After running this command, Git will save your changes in the stash.

git stash apply, on the other hand, is used to retrieve changes that you’ve saved in the stash and apply them to your working copy. When you run the git stash apply command, Git will apply the most recent stash to your working copy.

Here’s an example of how to use the git stash apply command:

    # Apply the most recent stash to your working copy
    git stash apply

If you have multiple stashes, you can apply a specific stash by specifying its index:

    # Apply the second stash to your working copy
    git stash apply stash@{1}

In summary, git stash is used to temporarily save changes that are not ready to be committed, and git stash apply is used to retrieve changes from the stash and apply them to your working copy. By using these two commands, you can save changes that you don’t want to commit yet but don’t want to lose either, and retrieve them later when you’re ready to continue working on them.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Git interview — then scores it.
📞 Practice Git — free 15 min
📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

All 100 Git questions · All topics