jraede jraede - 2 months ago 23
Git Question

Automatically add .gitignore and hooks on git init

Is there a way to tell git to automatically create/populate .gitignore and certain files in the .git/hooks folder every time

git init
is run on a certain machine? Maybe a global config somewhere?

We have symlinks that need to be ignored across the board, as well as pre-receive and post-receive hooks that need to be set up for every repo, so this would be easier than doing it manually for each one.

Thanks.

Answer Source

You can achieve this using a git template directory

git config --global init.templatedir /path/to/template

You can then add files to the folder /path/to/template/hooks and they will be automatically copied to the .git/hooks folder on git init

You can place the .gitignore contents you want in a file you name exclude in the folder /path/to/template/info. Then it will effectively be a .gitignore file in all new repositories created by git init

If you are on unix, there is even a default template directory /usr/share/git-core/templates