Sometimes I'm in a feature branch, but I've made an unrelated change that I want to see in master. Often I can just do:
git checkout master
git commit -m "..." filename
But sometimes when I do the checkout I get a warning that there are local changes and thus I can't switch the branch.
Why does this only happen sometimes? Is there a workaround when I see this message? Maybe stash?
As Devin Ceartas mentioned, this happens when switching branches would change some file that you've already changed locally. (Git won't complain when you have local changes on a file that would not be changed, or add new files that exist on neither the branch nor master.)
Two ways around this:
"git stash" your changes, change to master, and "git stash apply". Then commit the change.
Commit the changes you want on the branch, then "git stash" any other changes (if there are any), change to master, and cherry-pick the change on master.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With