I have been using Git for a while now. The projects that I have been working on have not been too complicated in regards to branches/tags.
Have you thought about worktrees?
$ git worktree add ../branch2 branch2
This will create a working tree checkout out to branch2
$ cd ../branch2
$ git branch
* branch2
You only have 1 local repo, but 2 different working areas, one for master and the other for branch2.
That way you can keep the object files separate as well.
Okay
So this question has been unanswered for a while now and I just been trying different solutions locally.
The best one I came up with is to use pre amd post checkoout hooks.
Here is what I have done
Create a .binaries
folder at the top level of your repository and add it to the .gitignore
file.
Add the file formats of the binaries to your .gitignore
file also.
write a script in your favorite scripting language to find all files of said format that moves them to the .binaries/<BRANCH>/
folder under the same path structure e.g. src/library1/lib1.o
should be MOVED to .binaries/<BRANCH>/src/library1/lib1.o
- this should be called by pre-checkout
Write a script to move files from the .binaries
folder into the current branch e.g. .binaries/<BRANCH>/src/library1/lib1.o
should be MOVED to src/library1/lib1.o
- this should be called by post-checkout
Now switching between branches will revert to the binaries that were built during for that branch only and you will have a clean checkout when creating a new branch.
The problem is that you need to get back the right binaries:
The last point is not overly important if you keep developing the latest versions of your 2 branches (and accept to rebuilt everything if you checkout an old tag and branch from there).
But still, if after a build you automatically publish those '.o' files into a repository made for managing binaries, that would solve your problem neatly.
A local Nexus repo for instance would be appropriate.
I usually solve these kind of problems by creating 2 clones of the repo to 2 separate folders (called customer_a and customer_b) and checkout branch1 in one folder and branch2 in the other folder.
Perhaps I'm missing something obvious, but when switching branches, Git won't touch untracked or ignored files, so if you build a product in one branch and then switch to another branch, the built products should remain.