CodeWhisperer CodeWhisperer - 1 year ago 76
Git Question

Automatically run tasks after Git Clone without using git hooks

Is it possible to run automatically a .bash script after running

git clone ..repo..
inside the terminal? At first I wanted to run commands like
rm -rf .git
composer install
inside the post-checkout hook but this file can only be used locally. So are there other options to do this?

Answer Source
mkdir ~/global_hooks
#create and edit the post-checkout inside
echo '#!/bin/bash' >> ~/global_hooks/post-checkout
echo 'rm -rf .git' >> ~/global_hooks/post-checkout
chmod 755 ~/global_hooks/post-checkout
git config --global core.hooksPath ~/global_hooks/

Any new clone with a checkout (without -n or --mirror or --bare) will trigger ~/global_hooks/post-checkout and .git will be removed. But this is not a good idea because you'll have to enable and disable the hook for different clones. Besides, every user needs to make the configuration, so it's a bit annoying.

What's worse, a git-checkout in a repository without disabling or overriding the global hook will remove its .git. So this is just for fun but not practical at all.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download