'how to apply same stash to different branches in git?

I have four branches lets say A B C D.

I worked on branch B for some function and created stash.

This feature I also want in branch A and D .

Is there any way that I can use this stash from B and apply to A and D also and definitely I want it on B too that's why I don't want to commit instantly and go for stash.



Solution 1:[1]

git checkout A
git stash apply
git checkout D
git stash apply

Git won't delete your stash until you call git stash drop, so feel free to apply it to as many branches as you like!

Solution 2:[2]

beaumontwebdev answer works good if you want different branches share the same stash.

if you have different stashes on different branches and you want to go back to your stashes on a particular branch. you need to do as follows:

git stash list

then pick out the stashes on your desired branch and to check what you have in that stash, you need to

git stash show stash@{1}

if you want to pop that stash out on your desired branch.

git stash apply stash@{1}

this link is the reference

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 beaumontwebdev
Solution 2 stoneshishang