I don\'t know if this is something common for people to do or not, but I personally always keep track of the number of times I built my code. That is, both the number of tim
Because the build number is not a feature of the branch you are in, it should be tracked differently. I don't use git, but for SVN, we have a system at work which builds a particular branch by copying it to a particular tag, adding some artefacts specific to that tag (your build number would be a prime example of the sort of thing to add), and committing only if the build succeeded.
In other words, there is a designated place (a tag name in SVN, or it could be a separate repo) where you only do builds, and this is the only place where you build, and that is where the build number information is stored and updated. Your build script would look something like
# I don't know git -- this is all very much pseudocode
# Where did you commit the code you want to build?
source=git://server/path/to/my/branch
# Replace builddir tree with yours
git replace git://server/special/place/build/thisproject with code from $source
cd /tmp
git checkout git://sever/special/place/build/thisproject into new builddir
cd builddir
update local version-controlled file buildnumber+=1
if make
# Build was successful
git commit buildnumber
copy build artefacts to where-ever
endif
cd /tmp
rm -rf /tmp/builddir
There is a race condition; if somebody checks in a build request after yours, but somehow ends up reaching the server first, you will end up building their check-in.
This can probably be made a lot simpler by using a designated build host like with Hudson/Jenkins.