GitCommandResult (@NotNull GitRepository repository, @NotNull String reference, @Nullable String newBranch, boolean force, boolean detach, boolean withReset, GitLineHandlerListener @NotNull ... listeners) { final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitCommand.CHECKOUT); h.setSilent(false); h.setStdoutSuppressed(false); if (force) { h.addParameters("--force"); } if (newBranch == null) { // simply checkout h.addParameters(detach ? reference + "^0" : reference); // we could use `--detach` here, but it is supported only since 1.7.5. } else { // checkout reference as new branch h.addParameters(withReset ? "-B" : "-b", newBranch, reference); } h.endOptions(); for (GitLineHandlerListener listener : listeners) { h.addLineListener(listener); } return runCommand(h); }