For the git part, you set --workspace_status_command to a script which retrieves the information, and then Bazel can feed that information into build targets. tools/buildstamp/get_workspace_status in the Bazel source tree is a good example of retrieving the git hash, and Bazel supplies the timestamp automatically.
Retrieving the values is rule-specific. The rule types I've done that with are cc_library and genrule. You can set the linkstamp attribute of a cc_library to a .cc file which will have BUILD_SCM_REVISION and BUILD_TIMESTAMP defined to the appropriate values when it's compiled. For a genrule, if you set the stamp attribute to 1 it will be able to access bazel-out/volatile-status.txt which has the information. I've seen Bazel code for doing something with a .properties file for Java code, but I've never actually figured out how to use it.