<p>You could always run <code>make clean</code> between builds but a lot of the time it won't be necessary and it is slower.</p>
<p>Pieter Wuille usually doesn't run <code>make clean</code> and only runs it when the build fails.</p>
<p>If it still fails after that he runs <code>git clean -dfx</code>. <strong>Warning</strong>: This deletes everything and resets your work directory to a fresh checkout. You'll need to <code>autogen.sh</code> again.</p>
<p>(Glen Willen suggests running <code>git clean -dfX</code> instead of <code>git clean -dfx</code> as X only removes ignored files, x also removes locally added non-ignored files, including e.g. new code you did not yet call <code>git add</code> on)</p>
<p><code>make clean</code> is only necessary when the configuration changes. This could be because you run <code>./configure</code> 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 <code>make clean</code> it will just see existing <code>.o</code> files not realizing that the rules used to build them have changed</p>
<p>Jon Atack usually doesn't run <code>make clean</code> but does if there is slight weirdness or if switching to fuzz build or back.</p>
<p>Thanks to Pieter Wuille, Jon Atack, Marco Falke and Glen Willen for answering this question on IRC.</p>

CC BY-SA 4.0
2020-10-29T21:23:16.113Z
2020-10-30T16:06:03.163Z
2020-10-30T16:06:03.163Z
Michael Folkson
<p>I am switching between <a href="https://bitcoin.stackexchange.com/questions/99014/how-do-i-build-and-review-a-bitcoin-core-gui-pull-request">building</a> different PR branches (ie I built one PR author's branch and now I am building a different PR author's branch).</p>
<p>Jon Atack's <a href="https://jonatack.github.io/articles/how-to-compile-bitcoin-core-and-run-the-tests" rel="nofollow noreferrer">doc</a> suggests:</p>
<blockquote>
<p>On the other hand, when you change the build configuration, and in some cases when testing different PRs, or when the build isn't working, it's often best to start with a clean slate using <code>make clean</code> or <code>make distclean</code> before configuring.</p>
</blockquote>
<p>Should I always run <code>make clean</code> in between builds?</p>
<p><strong>edit:</strong> Jon Atack has since updated his doc. Here is the updated guidance.</p>
<blockquote>
<p>On the other hand, when you change the build configuration (e.g. for a fuzz build), or you are building a branch containing substantial changes to the autoconf/automake scripts, or when the build isn't working, it's often best to start with a clean slate using <code>make clean</code> or <code>make distclean</code>.</p>
</blockquote>

<bitcoin-core-development><bitcoincore-review>
Should I always run "make clean" between building different PR branches of Bitcoin Core?
Michael Folkson
# Should I always run "make clean" between building different PR branches of Bitcoin Core?

(Asked by: username_0 on 2020-10-29)

I am switching between [building](https://bitcoin.stackexchange.com/questions/99014/how-do-i-build-and-review-a-bitcoin-core-gui-pull-request) different PR branches (ie I built one PR author's branch and now I am building a different PR author's branch).

Jon Atack's [doc](https://jonatack.github.io/articles/how-to-compile-bitcoin-core-and-run-the-tests) suggests:

> On the other hand, when you change the build configuration, and in some cases when testing different PRs, or when the build isn't working, it's often best to start with a clean slate using `make clean` or `make distclean` before configuring.

Should I always run `make clean` in between builds?

**edit:** Jon Atack has since updated his doc. Here is the updated guidance.

> On the other hand, when you change the build configuration (e.g. for a fuzz build), or you are building a branch containing substantial changes to the autoconf/automake scripts, or when the build isn't working, it's often best to start with a clean slate using `make clean` or `make distclean`.

**Tags:** bitcoin-core-development, bitcoincore-review


---

## 1 answers

### Answer by username_0 on 2020-10-29. Score: 1

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.


---

