Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically run Git hook when creating a Git tag

Is there a Git hook which can be executed when a new Git tag is added? Because I want to automatically write new Git tag names into a textfile. Do you have a clue on how to do this?

like image 237
Benny Neugebauer Avatar asked Nov 30 '10 01:11

Benny Neugebauer


People also ask

How do you trigger a pre-commit hook?

If you want to manually run all pre-commit hooks on a repository, run pre-commit run --all-files . To run individual hooks use pre-commit run <hook_id> . The first time pre-commit runs on a file it will automatically download, install, and run the hook. Note that running a hook for the first time may be slow.

What is pre-commit hook in git?

The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code.

How are git hooks executed?

The pre-receive hook is executed every time somebody uses git push to push commits to the repository. It should always reside in the remote repository that is the destination of the push, not in the originating repository.


1 Answers

While it's not currently possible using hooks, you can always create a simple script.

mytag.sh :

#!/bin/sh
[ -z "$1" ] || ( git tag $1 && git tag > /path/to/your-tags-file )

then :

chmod +x mytag.sh
git config alias.mytag !/path/to/mytag.sh
like image 161
OneOfOne Avatar answered Sep 18 '22 23:09

OneOfOne