How to move your Githooks to your Repo
📣 Sponsor
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
- How to make Git forget a tracked file now in .gitignore
- Using Git to see recent changes in specified a time period
- The Complete Beginners Guide to Getting Started with Git
- Git: Renaming a Branch
- Git Merge: Merging Changes from other Branches
- How to make Git ignore file permission (chmod) changes
- Resolving Git Merge Conflicts
- How to add a Blank Directory to your Git Repository
- Git Stash - Everything about stashing changes in git
- Setting upstream with Git