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?
I get the feeling you believe HEAD~3 means three commits back in the same order (wall clock time order) you made them. That’s not what it means, it means the 3rd generation ancestor of current HEAD, following only the first parents.
It doesn’t matter at all how you switch between branches.