Questions tagged [git-stash]

Allows to move pending changes in a working git directory away and restore them later, i.e. put them on a stash. You can have multiple stashes and it can also be used to move pending changes to another branch.

git stash allows you to stash changes in working directory, and then restoring them later, possibly on another branch.

Stashing changes is usually necessary when you need a clean working copy, e.g. before using or .

Popular questions

See also

References

$ git stash --help
675 questions
265
votes
5 answers

Stash changes while keeping the changes in the working directory in Git

Is there a git stash command that stashes your changes, but keeps them in the working directory too? So basically a git stash; git stash apply in one step?
Michael Dorst
  • 8,210
  • 11
  • 44
  • 71
264
votes
9 answers

Merge stashed change with current changes

I made some changes to my branch and realized I forgot I had stashed some other necessary changes to the said branch. What I want is a way to merge my stashed changes with the current changes. Is there a way to do this? It’s more for convenience, I…
Bemis
  • 3,092
  • 2
  • 17
  • 24
258
votes
7 answers

Git stash uncached: how to put away all unstaged changes?

Suppose two set of changes are made in a project versioned by git. One set is staged and the other is not. I would like to recheck staged changes by running my project at this state (before commit). What is a simple way to put away all unstaged…
klm123
  • 12,105
  • 14
  • 57
  • 95
238
votes
10 answers

What is the intended use-case for git stash?

If I work on branch A and suddenly need to work on branch B before being ready with a commit on branch A, I stash my changes on A, checkout B, do my work there, then checkout A and apply the stash. If I work on A and I want to stop working for the…
Alexander Popov
  • 23,073
  • 19
  • 91
  • 130
222
votes
3 answers

Undoing accidental git stash pop

I stashed some local changes before doing a complicated merge, did the merge, then stupidly forgot to commit before running git stash pop. The pop created some problems (bad method calls in a big codebase) that are proving hard to track down. I…
nren
  • 2,729
  • 3
  • 17
  • 11
206
votes
8 answers

Why does git stash pop say that it could not restore untracked files from stash entry?

I had a bunch of staged and unstaged changes and I wanted to quickly switch to another branch and then switch back. So I staged my changes using: $ git stash push -a (In hindsight I probably could have used --include-untracked instead of…
steinybot
  • 5,491
  • 6
  • 37
  • 55
203
votes
5 answers

git stash blunder: git stash pop and ended up with merge conflicts

I did a git stash pop and ended up with merge conflicts. I removed the files from the file system and did a git checkout as shown below, but it thinks the files are still unmerged. I then tried replacing the files and doing a git checkout again and…
Chirag Patel
  • 5,819
  • 8
  • 35
  • 38
187
votes
11 answers

Git stash pop- needs merge, unable to refresh index

I can't pop my stash because I merged a branch which apparently conflicts with my stash and now my stash is seemingly unable to be popped. app.coffee: needs merge unable to refresh index Anyone know how to resolve this?
RandallB
  • 5,415
  • 6
  • 34
  • 47
183
votes
5 answers

How can I format patch with what I stash away

In git, I stash away my changes. Is it possible that I can create a patch with what I stash away? And then apply that patch in some other repository (my co-worker's)? I know git format-patch -1, but I think that it's for what I have committed. But…
silverburgh
  • 8,659
  • 10
  • 31
  • 24
176
votes
5 answers

Can "git pull" automatically stash and pop pending changes?

I know how to solve this: user@host$ git pull Updating 9386059..6e3ffde error: Your local changes to the following files would be overwritten by merge: foo.bar Please, commit your changes or stash them before you can merge. Aborting But isn't…
guettli
  • 25,042
  • 81
  • 346
  • 663
154
votes
4 answers

What is the difference between IntelliJ's Shelve and Git stash?

IntelliJ supports git stashes as well as its own built in shelve command. These seem to be almost identical in purpose and utility. What is the difference between them?
Daniel Compton
  • 13,878
  • 4
  • 40
  • 60
152
votes
2 answers

How can I print the log for a branch other than the current one?

I'm on a branch with some changes. Changing branch is a pain as some files are locked by processes, so to change branch I'd have to stop all the processes which have locks, then stash the changes before checking out the other branch to see its…
BanksySan
  • 27,362
  • 33
  • 117
  • 216
152
votes
5 answers

Is git stash branch-specific or for the whole repository?

I went into a branch and did some work. I wanted to go into another branch but didn't want to commit so I did git stash. Then I did git checkout . I did some work there and, just like in the first branch, I wanted to switch out of it…
amphibient
  • 29,770
  • 54
  • 146
  • 240
151
votes
4 answers

Git stash twice

I had to quickly switch git branches, so I ran git stash, but I had to run it again because one of my files needed editing. So I've run git stash twice, and I'm ready to go back to editing my files. I ran git stash apply but I'm not convinced that…
stephenmurdoch
  • 34,024
  • 29
  • 114
  • 189
147
votes
7 answers

In git, is there a way to show untracked stashed files without applying the stash?

If I run git stash -u, I can stash untracked files. However, said untracked files don't show up at all with git stash show stash@{0}. Is there any way to show untracked stashed files without applying the stash?
Max Nanasy
  • 5,871
  • 7
  • 33
  • 38
1 2
3
44 45