bitcoincore development – Should I always run “make clean” between building different PR branches of Bitcoin Core?

You could always run make clean between builds but a lot of the time it won’t be necessary and it is slower.

Pieter Wuille usually doesn’t run make clean and only runs it when the build fails.

If it still fails after that he runs git clean -dfx. Warning: This deletes everything and resets your work directory to a fresh checkout. You’ll need to autogen.sh again.

(Glen Willen suggests running git clean -dfX instead of git clean -dfx as X only removes ignored files, x also removes locally added non-ignored files, including e.g. new code you did not yet call git add on)

make clean is only necessary when the configuration changes. This could be because you run ./configure with different flags or it could be because there are substantial changes to the autoconf/automake scripts when changing branches. Of course the act of changing branches isn’t relevant as the build system doesn’t know or care that you are using Git. The build system just sees some code and/or configure scripts changed and re-runs them as necessary. Without make clean it will just see existing .o files not realizing that the rules used to build them have changed

Jon Atack usually doesn’t run make clean but does if there is slight weirdness or if switching to fuzz build or back.

Thanks to Pieter Wuille, Jon Atack, Marco Falke and Glen Willen for answering this question on IRC.