This is the scenario:
- You are working on a feature branch
- You have made several new files, moved a few files and changed several other files
- While working on some code you didn't write, you notice and immediately fix a bug
- Alternatively, you notice a function is missing documentation so you quickly add some pro tips for the next developer that comes along
Then, you realize the last few changes you made doesn't belong in this feature branch. Instead, these changes should be committed to a different feature branch, a hotfix branch or even directly to develop.
Now, what is the most practical way to get your non-feature related changes committed to a different branch?
Elaboration
The "straight forward" way to handle this would be to stash your changes, check out the correct branch, commit your changes there, check out the feature branch again, pop the stash, resume working. (Optionally merge in the new branch.)
While simple in theory, this can be extremely impractical and tedious in many cases. First of all, the changes you want to move got stashed... So how exactly do you get them into the new branch? You could maybe pop the stash in the new branch? But if you are several commits deep into your feature branch, I wouldn't expect the current stash to be compatible with the develop branch.
I wish I could just commit the off-topic changes, then move that commit to a different branch with a single command, without leaving my current branch.
NB: I have seen other similar questions to this on SO, namely "how do I commit changes to a different branch without checking it out". The answers are pretty much always "you can't". But this is not what I'm asking here, I want to know the most practical way to get your changes moved to a different branch, when you're currently neck deep in a feature branch.