Use a build system that works with input-hashes.
djb's redo is an example.
Re:AMD Ryzen 9 3950X Review
by boring_twenties on Thursday November 14, 2019 @10:27PM
(#21541976)
Do you know about `git worktree`? You may not want a separate one for each branch you work on, but at least one for master and one for release would help you I think.
There are problems with worktree. But yes, I often do use multiple checkout directories. When you do the git clone using the --reference option it gets most of the objects from the referenced directories.
But this still results in slow compile times because the less used release directories get stale, have to be pulled up to date and often mostly rebuilt anyway. If I remember to actually use the second checkout directory, it does save on needing to rebuild the master/feature branches afterward.
Finish a feature branch and push it. Check out master. Pull master. Make new feature branch. Get an urgent bug fix request, switch to release branch, make a bugfix branch. Now go back to the new feature.
During this I may end up doing large rebuilds because Git changes modification times even if you end up back with the same header file you started with.
On a Thinkpad T540 the rebuild can take 30 minutes. It's less than 5 on a 3900X.