

If we want to remove a stash entry from the list when we apply it, we could use pop instead of `apply: git stash pop List all our current stashes: git stash list If we run git stash list after applying the stash, we’ll see the stash we applied is still there. poppingĪpplying a stash entry will keep a copy in the stash list – so we could apply the same stash entry to multiple branches. The most recent stash will have the reference stash list can contain stash entries from different branches, which could each be applied to other branches in your project. Subsequent stash entries are added to the beginning of the stash list. To apply a particular stash entry from our list, we can reference it with the apply command: git stash apply the last part with whichever stash reference we wish to use.)

Now, when we list our stash entries, we’ll see our custom message instead of the generic one: git stash On my-branch: my brand new WIP on my-branch: ca96af0 Commit message WIP on my-branch: 03af20c Commit message WIP on my-branch: 216b662 Commit message 1 This might not be very useful if we have multiple stash entries – it’s not very easy to see what changes we’ll be applying! Instead, we could save our stash with a custom message, so it’s easier to see what it relates to: git stash save 'my brand new stash' This will bring up a list that looks something like this: git stash WIP on my-branch: ca96af0 Commit message WIP on my-branch: 03af20c Commit message WIP on my-branch: 216b662 Commit message 1īy default, stash entries are named WIP (Work in Progress), followed by the branch and commit the stash entry was created from. To list all the stash entries, use git stash list. But it’s possible to store multiple stashes at the same time, and to apply them individually. Git stash apply will apply the last stash entry you created to your current working branch. To apply a stash entry including untracked files: git apply -u gitignore), we can add the -u (or -include-untracked) flag to our command:Ĭreate a stash entry including untracked files: git stash -u files that have not previously been staged, or files that are in our. If we want to create or apply a stash entry including untracked files (e.g. Stashing untracked filesīy default, git stash will only stash the tracked files. We can apply the stash entry to a different branch – it doesn’t have to be the branch that we created the stash from. To reapply our stashed changes at a later point, we can use git stash apply.Īpply a stash entry to your current working branch: git stash apply In its simplest form, the git stash command creates a stash entry. Stashing allows us to save a copy of our uncommitted changes on the current working branch. This is where Git’s stash command comes in useful. Or sometimes you might be working on a feature and you’re not ready to commit your changes yet, when someone asks you to fix an urgent bug and you need to jump onto another branch. When juggling multiple branches in Git, it’s easy to accidentally start working on the wrong branch, before realising you need to switch to another.
