Maven release:prepare fails to commit tag

Peter N. Steinmetz picture Peter N. Steinmetz · Jun 4, 2012 · Viewed 13k times · Source

Attempting to perform a release on a maven project, which has successfully released before.

When I perform mvn release:prepare I am prompted for the release tags and the new snapshot tags and the project builds.

But when it attempts to push to the remote, I get

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.0:prepare (default-cli) on project NeuralAnalysis: Unable to tag SCM [ERROR] Provider message: [ERROR] The git-push command failed. [ERROR] Command output: [ERROR] To ssh://[email protected]/NeuralAnalysis.git [ERROR] ! [rejected] NeuralAnalysis-1.5.6 -> NeuralAnalysis-1.5.6 (non-fast-forward) [ERROR] error: failed to push some refs to 'ssh://[email protected]/NeuralAnalysis.git' [ERROR] To prevent you from losing history, non-fast-forward updates were rejected

And indeed, attempting to perform git push ssh://[email protected]/NeuralAnalysis.git NeuralAnalysis-1.5.6 manually, also exits with the same complaint.

Performing git pull says 'Already up-to-date'. git branch shows I am on the 'master'. git push origin gives 'Everything up-to-date'.

Looking at the repository using Tower shows that 'master', 'origin/master' and 'NeuralAnalysis-1.5.6' are all the same and on the last commit. The working directory contains release.properties and pom.xml.releaseBackup files.

It looks to me like everything is fine with the repository overall.

Answer

Peter N. Steinmetz picture Peter N. Steinmetz · Jun 4, 2012

Turns out it was a remote tag with the same name, as suggested by VonC in the comment. This was likely created by some previously aborted release.

Although I found the remote tag by manually inspecting the refs/tags directory on the remote repository, git ls-remote --tags will show them as well and the git push --verbose will also show more about the problem in general.

To fix this, first retrieve the remote tags with git fetch --tags.

One way to perform the next step is then to simply bypass that release tag by updating the pom.xml to have a higher -SNAPSHOT version (including any references in the same project by other modules to that snapshot), check these in, and do mvn release:clean; mvn release:prepare over again.