Most IDEs (integrated development environment) integrate with the code formatter of your choice. It's best to add the configuration file to the code-base so all team members use the same configuration.
2. Linters
Code linters statically analyse code and quickly find mistakes such as potential exceptions thrown at runtime. Again, they come with a default or recommended set of rules for a programming language, however, the rule-set is highly customisable. Add the linter configuration file to the code-base to enforce rules across the team or project.
3. Static code analysis
Static code analysers go beyond what linters can do. They detect bug risks, anti-patterns, performance, and security issues. Have a look at LGTM or SonarCloud.
4. Local compile (optional)
Another quick-win is to add a partial or full project compile step as a pre-receive hook. It depends on project complexity and may not be feasible if the compile or build cycles take too long.

Image from the amazing article What Is Lint Code? And Why Is Linting Important?
Get started now - git pre-commit hook set up
If your team works on a Node.js / Javascript project here are some easy steps to get started.
Husky is an easy to set up git pre-receive hook.
1. Install
npx husky-init && npm install
It will setup husky, modify package.json and create a sample pre-commit hook that you can edit. By default, when you commit, it will run
npm test
To add the prettier code formatter run
npx husky add .husky/pre-commit "npx prettier --check ."
2. Run
The next git commit will run
./.husky/pre-commit

Since we're on the topic of Husky, I couldn't help but include a photo of my (not so) little boy Malakai.
What about Git pre-receive hooks?
Git pre-receive hooks are the police that check your code when you push it to the (git-remote) server aka Bitbucket, Github or any DVCS server. These checks can be slightly different from pre-commit checks. They can verify that your commit message is synced with a Jira issue that is marked as "In progress", or that there is no open pull request against the branch, or anything really that is required to streamline a team workflow.
As git pre-receive hooks run server-side they are usually configured by repository or project admins. Bitbucket server/data-center offers a wide range of hooks either built-in or installable via the Bitbucket app-store.
Bitbucket cloud has a limited amount of built-in pre-receive hooks and has zero flexibility when it comes to installable custom pre-receive hooks.
Conclusion
Now that you know a bit more about git pre-receive hooks and git pre-commit hooks, we encourage you to give it a try. Utilise the tools mentioned above to hit the ground running and be confident that your code is ready to go live.
What are your thoughts on git pre-receive and pre-commit hooks? We would love to hear about them below.
Want to take your team to the next level? Visit our Atlassian apps here or Book a Product Demo
Happy Coding!
Sean Manwarring
Head of Marketing at Izymes
Izymes’ mission is to eliminate boring from work. We build apps that turbo-charge team velocity through contextual automation.