I understand how to rebase using git rebase -i HEAD~X
where X is the number of previous commits you want to reference.
But say you were working on a branch and you make a commit. You then switch to a different branch and do some work there. You keep doing this back and for a couple days, let's say.
Eventually if you want to squash one of your branches you won't be able to do that because doing something like HEAD~3
will reference commits from different branches.
I guess my question is really: how do I squash all the commits on a branch without squashing unrelated commits into it as well?