After searching the forum it seems that most people use a separate project
for each branch. I wonder what is the "official" way to switch between
branches. Is there some document saying how to create new branches and keep
projects configurations in sync?
In case someone is interested, this is how I switch between branches. There
is one project which includes sources from all branches. The branch I work
in is marked as "source code" in module configuration. The rest of the
branches are marked as "excluded". To switch to another branch I exclude
current branch sources and unexclude sources of another branch. The only
problem is that after switching like this IntelliJ continues to use classes
from the last branch (and sometimes even fails to run project reporting
errors which do not exist) what can be very confusing. Rebuilding the
project solves the problem.