I have two branches, say B1 and B2. I'm in B2 and I have staged and unstaged files.
I want the staged files to be committed in B1 (I thought I was in B1 when I git add-ed the files) and the unstaged ones to be committed in B2.
Is it possible? How?
I'm sure there's a more elegant way but all I could come up with is:
EDIT
This question has a detailed answer that does more or less what I've suggested.
git stash is really powerful when it comes to move dirty changes between branches. In your case, you can apply these steps:
git stash --keep-index, this will stash only unstaged filesgit stash, this will stash the rest, i.e. staged filesgit stash pop, staged files will be moved to B1git stash pop, unstaged files will be moved to B2After that, you can commit the changes in each branch individually.
 
    
    If the modfied staged and unstaged files does not change by switching to branch B1, you can switch branches without affecting anything, then you can easily commit your files and switch back to B2.
However if your modified files are changed between B1 and B2, you cannot switch branches. In this case, you have to stash your changes before swithcing branches.
git stash --keep-index to stash and keep staged filesgit reset HEAD to unstage staged filesgit stash to stash your previousely staged filesgit checkout B1 to switch to B1 branchgit stash pop to unstash and remove your last stashgit commit -a to commit your previousely staged files on B1git checkout B2 to switch to B2 branchgit stash popgit commit -a commit all the remaining changes on B2Be carefull with these commands! I'm not a git pro! :-)
