Skip to content

2nd git.commit error: "On branch main nothing to commit, working tree clean" #1530

Description

@loelkes

Description

Commitizen fails if version_provider is set to scm and no files are changed (no changelog, no version number in files) a version bump

Steps to reproduce

  1. Create en empty repository with git init test and change into it cd test
  2. Add a configuration cz.toml
[tool.commitizen]
version_provider = "scm"
  1. Commit it with git add cz.toml and cz commit
  2. Run cz bump
bump: version 0.0.0 → 0.0.1
tag to create: 0.0.1
increment detected: PATCH

[main 16e057b] bump: version 0.0.0 → 0.0.1
 1 file changed, 1 insertion(+), 1 deletion(-)

Done!
  1. Add another file / make another changer with touch foobar, git add foobar and cz commit
  2. Run cz bump
bump: version 0.0.1 → 0.0.2
tag to create: 0.0.2
increment detected: PATCH

2nd git.commit error: "On branch main
nothing to commit, working tree clean
"

If I run cz bump --changelog the second time, there is no error.

Current behavior

cz bump fails if no changes (updated changelog, version number in files) are made during a version bump.

Desired behavior

cz bump should not fail if no changes (updated changelog, version number in files) are made during a version bump.

Screenshots

No response

Environment

Commitizen Version: 4.8.2
Python Version: 3.13.4 (main, Jun 3 2025, 15:34:24) [Clang 17.0.0 (clang-1700.0.13.3)]
Operating System: Darwin

Activity

  1. Lee-W commented on Jun 10, 2025

    @Lee-W
    Member

    With update_changelog_on_bump = true, it works fine, but this is a valid bug. Thanks for reporting!

  2. added theissue type on Jun 10, 2025
  3. loelkes commented on Jun 10, 2025

    @loelkes
    Author

    This came to light while building a workaround for #883

    Since I can't use the changelog due to this bug I run cz bump without --changelog / update_changelog_on_bump = true

  4. woile commented on Jun 10, 2025

    @woile
    Member

    There's a PR open supposed to fix this
    #996

  5. Lee-W commented on Jun 11, 2025

    @Lee-W
    Member

    oh.... I'll see whether I can make it merged in the next release

  6. bearomorphism commented on May 9, 2026

    @bearomorphism
    Collaborator

    Triage from #1964: Confirmed still valid on master (4.15.1). commitizen/commands/bump.py (lines 385-394) calls git commit -a and treats a non-zero return code as fatal. With version_provider = "scm" and no version_files / changelog updates, there's nothing for the bump commit to include, so git exits with "nothing to commit". Fix should detect this case (e.g., check is_staging_clean() before commit, or treat the "nothing to commit" return code gracefully) and skip the bump commit, just creating the tag on HEAD.

  7. bearomorphism commented on May 9, 2026

    @bearomorphism
    Collaborator

    Verification update (re #1964)

    Reproduced against current master (4.15.1):

    Config: version_provider = "scm" only, no version_files, no changelog updates.

    After staging cz.toml and committing feat: initial, running cz bump --yes exits 6 with:

    bump: version 0.0.0 → 0.1.0
    tag to create: 0.1.0
    increment detected: MINOR
    2nd git.commit error: "On branch main
    nothing to commit, working tree clean
    "
    

    No tag is created. Even the first bump fails because there are no files to update.

    Verdict: STILL VALID — and slightly worse than the original report, which had the first bump succeed (probably because of cz.toml modifications by older commitizen versions).

    Suggested fix in commitizen/commands/bump.py:

    • Before calling git.commit(...), check whether anything is staged (git.is_staging_clean()).
    • If clean, skip the commit and just create the tag on HEAD.
    • This naturally handles the version_provider = "scm" no-op-bump case without requiring users to set update_changelog_on_bump.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions