It is common practice to make the android:versionCode in the AndroidManifest.xml the build number of the application. An easy build number to calculate is the number of git commits in the repo.
Instead of having to edit the manifest file manually and update the android:versionCode attribute with the build number, below is a git pre-commit hook that does it for you.
#!/usr/bin/env bash
MANIFEST="AndroidManifest.xml"
if [ -f $MANIFEST ]
then
COMMITNUM=`git log --pretty=format:'' | wc -l | tr -d ' '`
INCREMENTED=$(($COMMITNUM+1))
sed "s/android:versionCode=\"[0-9]*\"/android:versionCode=\"${INCREMENTED}\"/" $MANIFEST > $MANIFEST.tmp && mv $MANIFEST.tmp $MANIFEST
git add $MANIFEST
echo "Updated Build Number To ${INCREMENTED} In ${MANIFEST}!";
fi
Copy and paste the above code into .git/hooks/pre-commit, creating the file if necessary. Also ensure the hook is executable by running the following:
chmod +x .git/hooks/pre-commit