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...'
Written by Adam Stankiewicz
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#