Put current git branch to project version

I want to put the current git branch into the version field in pom xml. I found some post in the internet suggesting to do something like:


but this seems not to work with git. Are there any other solutions?

  • How to avoid putting authentication data in version control?
  • How can I have grep not print out 'No such file or directory' errors?
  • Change Avatar Next to GitHub Username (For Commits)
  • git pull error :error: remote ref is at but expected
  • Git ignore files being tracked WITHOUT DELETING THEM
  • Error starting Git Bash in windows 7
  • How to add two projects from one workspace to git in IntelliJ Idea?
  • Cannot use SSL certificate when using Git on openSUSE
  • Git doesn't work after a clean installation using macports due to libcurl.4.dylib version?
  • Is putting all project dependencies inside project's repository good practice?
  • GitHub revert or reset?
  • Branch only 1 or 2 files in git for android project
  • 2 Solutions collect form web for “Put current git branch to project version”

    Yes, use the git commit id plugin for maven

    It’s pretty straightforward. You can use it to get the git branch with


    So in your case it would go:


    i created a plugin for this behavior (and by extend to link sonar to my maven projects).

    The only thing you need to do is

    add following plugin to your pom.xml


    call the plugin to set the git branch

    mvn com.viae-it.maven:sonar-maven-plugin:set-git-branch

    then you can use the sonar.branch property

    Git Baby is a git and github fan, let's start git clone.