How to create a branch from a stash?

git stash branch branch_name stash_name

To create a new branch from any stash use git stash branch branch_name stash_name. The new branch will be checked out and the selected stash dropped.

The stash_name parameter is optional, leave it empty and git will create a branch from your last stash.

Layer 1
Terminal Example
git stash list
stash@{0}: On main: my_stash
stash@{1}: WIP on main: 0e9c1e9 Readme changes
stash@{2}: WIP on main: 0e9c1e9 Readme changes
stash@{3}: WIP on main: c335861 Changes in code and README

git stash branch branch-from-stash
Switched to a new branch 'branch-from-stash'
On branch branch-from-stash
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git restore ..." to discard changes in working directory)

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (8114a704f1e3353ea789efc59f4453a75f1de5d3)    ],

See git stash to learn more about it.

Last modified on November 30, 2021.

You might also like