Skip to main content

Questions tagged [githooks]

Git hooks are scripts that are executed upon certain Git events. Events include, but are not limited to, pre- and post-commit and pre- and post-rebase on the client-side, and post-receive-commit on the server-side. No need to use the tag Hooks when using the tag Githooks. Maybe used in combination with tag Webhooks

Filter by
Sorted by
Tagged with
1107 votes
7 answers
679k views

Skip Git commit hooks

I'm looking at a Git hook which looks for print statements in Python code. If a print statement is found, it prevents the Git commit. I want to override this hook and I was told that there is a ...
Ben's user avatar
  • 16.1k
524 votes
15 answers
149k views

Can Git hook scripts be managed along with the repository?

We'd like to make a few basic hook scripts that we can all share -- for things like pre-formatting commit messages. Git has hook scripts for that that are normally stored under <project>/.git/...
Pat Notz's user avatar
  • 212k
419 votes
19 answers
128k views

Deploy a project using Git push

Is it possible to deploy a website using git push? I have a hunch it has something to do with using git hooks to perform a git reset --hard on the server side, but how would I go about accomplishing ...
Kyle Cronin's user avatar
  • 78.6k
343 votes
28 answers
938k views

Git push error pre-receive hook declined

I have run gitlabhq rails server on virtual machine, following 1-6 steps from this tutorial https://github.com/gitlabhq/gitlab-recipes/blob/master/install/centos/README.md and starts rails server ...
Hroft's user avatar
  • 4,107
337 votes
4 answers
105k views

Applying a git post-commit hook to all current and future repositories

I've written a Git post-commit hook and it works correctly. However, I want to add this hook to apply to all current (and future) Git repositories I am working on. I tried adding the hook to my ~/....
swanson's user avatar
  • 7,617
327 votes
10 answers
157k views

Putting Git hooks into a repository

Is it considered to be a bad practice - to put .git/hooks into the projects repository (using symlinks, for example). If yes, what is the best way to deliver same hooks to different Git users?
shabunc's user avatar
  • 24.3k
303 votes
18 answers
255k views

update package.json version automatically

Before I do a small release and tag it, I'd like to update the package.json to reflect the new version of the program. Is there a way to edit the file package.json automatically? Would using a git ...
tUrG0n's user avatar
  • 4,388
242 votes
17 answers
180k views

Make Git automatically remove trailing white space before committing

I'm using Git with my team and would like to remove white space changes from my diffs, logs, merges, etc. I'm assuming that the easiest way to do this would be for Git to automatically remove trailing ...
mloughran's user avatar
  • 11.7k
195 votes
6 answers
155k views

How can I manually run a Git pre-commit hook, without attempting a commit?

I just want to be able to run it to see if the code in my working tree passes it, without actually attempting a commit.
callum's user avatar
  • 36.7k
183 votes
1 answer
79k views

How can I have linked dependencies in a git repo?

In my scripts, I often use libraries (mine or others') that have their own repos. I don't want to duplicate those in my repo and get stuck with updating them every time a new version comes out. ...
Lea Verou's user avatar
  • 23.8k
154 votes
5 answers
149k views

How to remove git hooks

I had set up a git hook in pre-commit file to run git pull before any commit. Now I have deleted that file and restarted my computer multiple times, but that hook is still running before my commits. ...
Ali Farhoudi's user avatar
  • 5,800
122 votes
3 answers
50k views

Are git hooks pushed to the remote when I 'git push'?

If I create a new hook script in my local repository in repo/.git/hooks/post-commit and then I run "git push" are the hooks pushed to the remote? Then, when the other developers run "git pull" from ...
slacy's user avatar
  • 11.7k
106 votes
6 answers
34k views

Symbolic link to a hook in git

I wrote my own custom post-merge hook, now I added a "hooks" directory to my main project folder (since git doesn't track changes in .git/hooks), somewhere I read that I can make a symbolic link from ...
Mateusz Dymczyk's user avatar
106 votes
11 answers
97k views

Git hook to send email notification on repo changes

How do I configure the appropriate Git hook to send a summary email whenever a set of changes is pushed to the upstream repository?
Head's user avatar
  • 4,721
105 votes
11 answers
120k views

Why is my Git pre-commit hook not executable by default?

If you see the accepted answer in: Aggregating and uglifying JavaScript in a Git pre-commit hook, you'll see that I had to do a chmod +x on my pre-commit hook to get it to work. Why is this not ...
Josh Smith's user avatar
  • 14.9k
104 votes
8 answers
70k views

How can I automatically push after committing in Git?

How do I set Git to automatically push to a remote repository (including automatically providing my passphrase) after each commit to the local repository?
ulu's user avatar
  • 6,012
104 votes
11 answers
55k views

Can a Git hook automatically add files to the commit?

I'd like to add an automatically generated file to the same commit using a pre- or post-commit hook in Git, dependent on the files that were modified in that commit. How would I go about this? I've ...
Ian Terrell's user avatar
  • 10.8k
99 votes
5 answers
24k views

getting "fatal: not a git repository: '.'" when using post-update hook to execute 'git pull' on another repo

I'm new to git so I apologize (and please correct me) if I misuse terminology here, but I'll do my best. I'm trying to set up a bare git repo (hub) and a development site working copy (prime) on a ...
Ty W's user avatar
  • 6,774
95 votes
13 answers
69k views

How can I automatically deploy my app after a git push ( GitHub and node.js)?

I have my application (node.js) deployed on a VPS (linux). I'm using git hub as a repository. How can I deploy the application automatically, on git push ?
Advanced's user avatar
  • 1,507
82 votes
8 answers
40k views

Git remote/shared pre-commit hook

With a one official repository as the remote, and multiple local repositories cloned from it, can a pre-commit hook be scripted on that main repository and be enforced on all clones of it?
Samer Buna's user avatar
  • 9,131
81 votes
8 answers
123k views

Is there a way to lock individual files or directories on fork when using git?

We are a team of 60+ developers working on the same product and are moving from SVN to Git and GitHub. We have a process in SVN where in individual files are locked and whenever a developer wants to ...
Karthick S's user avatar
  • 3,244
80 votes
6 answers
15k views

Tracking changes to hooks in .git/hooks

Is there a way to track git hook changes? I have three hooks that only show up on my machine, not when my other developers fetch. Trying to git add doesn't work.
Hans's user avatar
  • 3,503
75 votes
8 answers
55k views

Local executing hook after a git push? (post-push)

I've looked at the githooks manpage but unless I'm missing something I don't see an option for local, post-push git hooks. I'd like to have one that updates the api docs on my web server (for which I ...
scotchi's user avatar
  • 2,389
70 votes
3 answers
25k views

When I "git push" git now says "Create pull request for ...". Why?

I am making changes to a project in a branch that, so far, is known to no one else but me. However, starting recently, when I git push to this project, I now receive this as part of the response: ...
Mike Robinson's user avatar
66 votes
7 answers
44k views

black as pre-commit hook always fails my commits

I'm trying to use pre-commit to manage Black as a Git pre-commit hook, but I must be doing it wrong. In my pre-commit config file I have: - repo: https://github.com/psf/black rev: 19.3b0 ...
Jean-François Corbett's user avatar
64 votes
9 answers
90k views

Git pre-commit hook is not running on Windows

I'm just starting to look into Git hooks, but I can't seem to get them to run. I set up a local repository, so there is now a '.git' directory in my project folder. I have added a '.cmd' file into the ...
user1578653's user avatar
  • 5,018
64 votes
3 answers
45k views

How would I write a pre-merge hook in Git?

The question says it all. Is there a way to perform an action before a merge? I'm guessing there's a way to make use of a pre-commit hook, but I'm not quite sure.
joshin4colours's user avatar
62 votes
4 answers
44k views

Is there a way to trigger a hook after a new branch has been checked out in Git?

Is there a way to trigger a hook after a new branch has been checked out in Git?
netflux's user avatar
  • 3,818
55 votes
4 answers
43k views

Post Commit Hook Not Running

My post commit hook is not running after git. I have verified that the hook does work if I just run it from the terminal. The code in the hook is: #!/bin/sh #.git/hooks/post-commit # An example ...
Dave Long's user avatar
  • 9,719
54 votes
10 answers
24k views

Running PowerShell scripts as git hooks

Is it possible to run PowerShell scripts as git hooks? I am running git in a PowerShell prompt, which shouldn't make any difference, but I can't seem to get them to work, as the hooks are named ...
Erick T's user avatar
  • 7,309
53 votes
3 answers
24k views

Handle multiple pre-commit hooks

I have a need to use multiple pre-commit hook scripts. Not sure how to handle them. Should all of them be combined into one single large pre-commit script? If not, how to handle multiple pre-commit ...
karthik101's user avatar
  • 1,679
49 votes
1 answer
24k views

github server-side git hooks (i.e. pre-commit and post-commit)

I've looked around the answers on SO, and the web, and I can't see anything on how to set up a server-side git hook on github (as opposed to webhooks). Is there a way to do this? Or alternatively, is ...
Marcin's user avatar
  • 49.4k
47 votes
4 answers
41k views

change default git hooks

Not sure if this is possible in git (I haven't found it but I may be using the wrong vocabulary in my searches), but it be would useful to be able to modify and enable hooks as the defaults for all ...
rplevy's user avatar
  • 5,443
43 votes
5 answers
31k views

git hooks : is there a clone hook?

We want to store some meta-information about the commit in an external database. During a clone or a checkout, this database should be referred and we copy the meta information to a file in the repo ...
maxmelbin's user avatar
  • 2,075
41 votes
2 answers
44k views

How to execute a command right after a fetch or pull command in git?

I cloned the GHC (Glasgow Haskell Compiler) repository. In order to build the compiler, you need several libraries, all of them are available as git repositories too. In order to ease ones live, the ...
fuz's user avatar
  • 91.3k
41 votes
3 answers
13k views

Commit in git only if tests pass

I've recently started using git, and also begun unit testing (using Python's unittest module). I'd like to run my tests each time I commit, and only commit if they pass. I'm guessing I need to use ...
Skilldrick's user avatar
  • 70.2k
38 votes
1 answer
23k views

Find Git branch name in post-update hook [duplicate]

I'm executing a programme to alert CruiseControl each time an update is sent to our remote repository. I'm using a Git post-update hook for this. It would be great if I could find out which branch ...
user489998's user avatar
  • 4,511
37 votes
2 answers
32k views

How to set up a Git hook so that after pushing to ssh://[email protected]/~/bar.com.git, it will go to ~/bar.com and do a git pull?

I was advised to set up on a remote server foo.com/~/bar.com # live webpage content foo.com/~/bar.com.git # a bare repo so, from my local machine, I can do a git push and it will push to ...
nonopolarity's user avatar
37 votes
2 answers
9k views

git commit in pre-push hook

I have added something like that in pre-push hook: gs0=$(git status) pip-dump gs1=$(git status) if [ "gs0" != "gs1" ] then git commit -m "pip-dump" fi (this is updating my pip requirements file) ...
lajarre's user avatar
  • 5,092
36 votes
4 answers
17k views

Run Create-React-App Tests not in Watch Mode

I have a project created using Create-React-App. I am looking to add in a precommit hook to run our linter and tests with the pre-commit package. "pre-commit": [ "precommit-msg", "lint", "test" ...
DoomageAplentty's user avatar
36 votes
1 answer
31k views

How do I react to new tags in git hooks?

I'd like to set up a git hook that creates a CDN-style directory structure based on incoming tags. So, for example, if the last tag in the local repository is "v1.2.1" and I pull a commit with "v1.2.2"...
futuraprime's user avatar
  • 5,548
34 votes
4 answers
13k views

Git receive/update hooks and new branches

I have a problem with the 'update' hook. In the case of a new branch, it gets a 0000000000000000000000000000000000000000 as the 'oldrev'. And I don't know how to handle that case. We have the ...
marc.guenther's user avatar
33 votes
2 answers
54k views

Git hooks : applying `git config core.hooksPath`

I have a git repository with a pre-commit hook set up : my-repo |- .git |- hooks |- pre-commit # I made this file executable Until there, everything works. The hook is running when I ...
Nicolas Marshall's user avatar
33 votes
3 answers
5k views

Chaining git hooks

As many of you probably know, there can be only one hook type in git. If two update hooks need to be evaluated. The git admin is left with two unmanageable solutions: Merge the hook scripts together ...
Olivier Refalo's user avatar
32 votes
3 answers
11k views

bypass pre-commit hook for merge commits

I setup some git hooks to run some gulp commands on pre-commit. I basically run jshint/plato. I basically want to bypass these for two cases: hotfix branches (master / hotfix) git merge (or find a ...
Nix's user avatar
  • 58k
32 votes
7 answers
27k views

Append ticket number using git commit hooks?

So my branch is named after bugtracker ticket number, something like "issue-1234", and we have a convention to always write down ticket number in commit message. I'm wondering if it's possible to ...
EnToutCas's user avatar
  • 1,317
31 votes
6 answers
13k views

Automatically copy pushed files from one GitHub repository to another

I have two GitHub repositories. I'd like to automatically (probably using hooks and/or github API) commit and push files to the second repository when they are pushed to the first one. The second ...
Drax's user avatar
  • 13.1k
31 votes
5 answers
10k views

How to detect commit --amend by pre-commit hook ?

When I do commit --amend, it is unsafe commit if the commit already has been pushed to remote repository. I want to detect unsafe commit --amend by pre-commit hook and abort. But pre-commit hook has ...
ton's user avatar
  • 1,614
31 votes
1 answer
16k views

Best way to debug git-hooks

What is the best way to debug git-hooks? The way I prefer is adding statements to add output to a log file. For example, the following. echo 'post-receive executed' >> hooks.log Is there a ...
Muhammad Kashif Nazar's user avatar
30 votes
3 answers
30k views

Writing Git hooks in python/bash scripts [closed]

I have recently needed to write git hooks, for all commits to reference a particular ticket. I was hoping for a place to start learning. All the stuff in the pro git book is written in Ruby. Since ...
Mahdi Yusuf's user avatar
  • 20.7k

1
2 3 4 5
36