Last Updated: February 25, 2016
·
2.181K
· sheerun

Stash all non-staged files.

Say, you've modified some code in the feature branch and you want to commit some part of it to the develop branch. Here's how:

add Gemfile # stage files you want to change
git stash -k -u # stash all other files

git checkout develop
git commit -m "Fresh gemfile."

git checkout feature
git stash pop # unstash changes and keep going

If you're getting "error: Your local changes to the following files would be overwritten by checkout:" message, then try following:

add Gemfile # stage files you want to change
git stash -k -u # stash all other files
git stash # stash changes you want to make

git checkout develop
git stash pop # unstash changes you want to make
git commit -m "Fresh gemfile."

git checkout feature
git stash pop # unstash rest of changes and keep going

Also, I encourage you to use short description for stashes. If you do so, it's easier to remember what changes they contain later:

git stash save --all -m 'Going for a coffee...'