Increase version number with each git commit

158 Views Asked by At

I would like to automate assigning version number with each git commit, according to major.minor.patch scheme.

For instance, start with commit version 1.0.0. The next commit will be version 1.0.1, and the next commit is going to be 1.0.2 automatically. etc..

Also, I would like the ability to increment different parts of the scheme (minor, major) with a certain command or flag.

Is there a convenient way with a git command to do so, or perhaps use some an external versioning tool?

1

There are 1 best solutions below

0
Ujjwal Raut On

You can use Python scripting in this case - save the current version string in a file, or any other preferable choice which can be pushed to the repository. This will ensure that whenever you are cloning the repository, you can easily and locally fetch the current version string for usage.

Then some wrapper logic is required, which will execute shell commands in Python for creating new branch using git CLI. While executing that command, the submitted version string as branch name will be the saved current version string incremented by one. After the branch is successfully created, update the saved string with the one with which the branch is created