How to move your Githooks to your Repo
If you're like me, you like to automate things when you push or pull them from a repo. Git Hooks are files which are run when you do an action, such as merge.
If you're also like me, you may have noticed that githooks are only relevant to that particular git location, as they are stored in the
.git folder. You can however store your githooks in your repo, so they are available and run in every location, whether remote, local, or anything in between.
1. Create the folder
First of all, in your git repository, create a folder called
.githooks. You can actually call it whatever you want, but I find
.githooks makes the most sense.
2. Update Git
Next, update Git so that it uses that folder as your git repository. You can do this in Git 2.9 and above by using the following command:
git config core.hooksPath .githooks
If you do not have git 2.9 and above, you will have to update, since this functionality is not available before!
Once you've done that, your git repository will include your githooks in one folder, and will run them out of that folder. So if you put a
post-merge file in you
.githooks folder, it will run after you run the git merge command.
Now you can commit your git hooks to your repo, and other branches, allowing you to keep consistent versioning on your git automations.
More Tips and Tricks for Git
- A Step by Step Guide to Git Branches
- Git Stash - Everything about stashing changes in git
- How to undo a git pull
- How to move your Githooks to your Repo
- Resolving Git Merge Conflicts
- Git blame - How to find out who modified a line with Git
- How to force overwrite local changes with 'git pull'
- Using Git to see recent changes in specified a time period
- How to add a Blank Directory to your Git Repository
- How to amend and update a git commit