You can certainly do this, not sure why, but it is possible.
Note, git uses branches, so you have to know what branch is your main branch, let's assume master
.
Use the git log
command with some options to get the commit id from the remote HEAD on your main branch.
$ git log origin/master -n 1 --pretty=format:"%H"
Output this to a file.
$ git log origin/master -n 1 --pretty=format:"%H" > top_commit.txt
Put this in a shell script so you can reuse.
Add a githook to the desired event, which I assume will be pre-commit
. For more on that, see https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks.
There are some limits to what you can do. For instance, I know you can do this for pre-commit, but not sure about the need to do so when cloning. Also, client side githooks will have to be installed. You'll need to write a script to install those for your users.
UPDATE
Something akin to what you are asking is possible, but not exactly; I do not think it possible to grab the commit being made and shove it in a file, then include that file in the same commit.
Furthermore, I'm not sure why you want to do this as git log
has a full history of what occurred.
There are valid reasons to want to know and use the commit id at HEAD, but we'd need to know why, when, where, how, etc., to help you further.