How can I auto-update a metadata file on each commit using Git/GitHub Desktop? #163400
-
I’m working with a local GitHub repository using GitHub Desktop to manage commits and pushes. I’d like to automatically update a metadata block (in a for example .pl script) with details like: - date - author - Version number . I know Git stores this info internally, but I want a visible file in the repo that updates with each commit. GitHub Desktop doesn’t support Git hooks—so what are the best workarounds? Can I use a script that runs before each commit to extract Git info and update metadata block inside the files? Any tools, patterns, or ideas from folks who've tackled something similar would be much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
This comment was marked as off-topic.
This comment was marked as off-topic.
-
Create a script that: Extracts Git info. Updates metadata in target files. Runs before you manually commit in GitHub Desktop. Example (Bash or PowerShell): Get Git infoauthor=$(git config user.name) File to updatefile="script.pl" Replace metadata blocksed -i '' -E "s/^# Author:./# Author: $author/" "$file" or Use Git GUI With Hook Support (Optional Switch) Terminal-based Git clients (with pre-commit hooks) These allow custom Git hooks, where you can add a pre-commit script to auto-update files. |
Beta Was this translation helpful? Give feedback.
Hey @ghareh-gozlou 👋
Awesome question — I’ve tackled something similar when I wanted auto-updated metadata blocks (especially for tracking versioning and timestamps). Since GitHub Desktop doesn't support Git hooks, here are a few flexible workarounds you can try:
Option 1: Use a Pre-commit Script + Git Alias
Even though GitHub Desktop doesn't run hooks directly, you can:
Write a small script (e.g., in Python, Bash, or PowerShell) to:
.pl
or target filegit config user.name
)git rev-parse HEAD
)Create a Git alias or a simple double-cl…