Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No stash found when using git stash branch

Tags:

git

git-stash

Using git, I am working on the master branch and have a few unadded and uncommitted files. I don't want to add them or commit them to the master. Instead, I am trying to stash the files and move to a new branch to add them and commit them there. However, this is failing with the error message: "No stash found.". Please see the log below:

$git status

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   Makefile
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   newfile.c
no changes added to commit (use "git add" and/or "git commit -a")

And then when I try to use git stash

$git stash branch mywork
No stash found.

I am pretty sure the I used git stash in a similar manner before, but I can't see why it is failing now. How can I stash my changes to another branch and commit them there?

like image 862
MaACAn Avatar asked Sep 05 '25 16:09

MaACAn


1 Answers

The git stash branch command creates a new branch from an already existing stash. Because you don't have an existing stash yet, you get the error message.

Just use git stash and after that, if you want to create a new branch from this stash, git stash branch mywork.

like image 137
Sven Koschnicke Avatar answered Sep 07 '25 09:09

Sven Koschnicke