ThoughtWorks
  • Contact
  • Español
  • Português
  • Deutsch
  • 中文
Go to overview
  • Engineering Culture, Delivery Mindset

    Embrace a modern approach to software development and deliver value faster

    Intelligence-Driven Decision Making

    Leverage your data assets to unlock new sources of value

  • Frictionless Operating Model

    Improve your organization's ability to respond to change

    Platform Strategy

    Create adaptable technology platforms that move with your business strategy

  • Experience Design and Product Capability

    Rapidly design, deliver and evolve exceptional products and experiences

    Partnerships

    Leveraging our network of trusted partners to amplify the outcomes we deliver for our clients

Go to overview
  • Automotive
  • Cleantech, Energy and Utilities
  • Financial Services and Insurance
  • Healthcare
  • Media and Publishing
  • Not-for-profit
  • Public Sector
  • Retail and E-commerce
  • Travel and Transport
Go to overview

Featured

  • Technology

    An in-depth exploration of enterprise technology and engineering excellence

  • Business

    Keep up to date with the latest business and industry insights for digital leaders

  • Culture

    The place for career-building content and tips, and our view on social justice and inclusivity

Digital Publications and Tools

  • Technology Radar

    An opinionated guide to technology frontiers

  • Perspectives

    A publication for digital leaders

  • Digital Fluency Model

    A model for prioritizing the digital capabilities needed to navigate uncertainty

  • Decoder

    The business execs' A-Z guide to technology

All Insights

  • Articles

    Expert insights to help your business grow

  • Blogs

    Personal perspectives from ThoughtWorkers around the globe

  • Books

    Explore our extensive library

  • Podcasts

    Captivating conversations on the latest in business and tech

Go to overview
  • Application process

    What to expect as you interview with us

  • Grads and career changers

    Start your tech career on the right foot

  • Search jobs

    Find open positions in your region

  • Stay connected

    Sign up for our monthly newsletter

Go to overview
  • Conferences and Events
  • Diversity and Inclusion
  • News
  • Open Source
  • Our Leaders
  • Social Change
  • Español
  • Português
  • Deutsch
  • 中文
ThoughtWorksMenu
  • Close   ✕
  • What we do
  • Who we work with
  • Insights
  • Careers
  • About
  • Contact
  • Back
  • Close   ✕
  • Go to overview
  • Engineering Culture, Delivery Mindset

    Embrace a modern approach to software development and deliver value faster

  • Experience Design and Product Capability

    Rapidly design, deliver and evolve exceptional products and experiences

  • Frictionless Operating Model

    Improve your organization's ability to respond to change

  • Intelligence-Driven Decision Making

    Leverage your data assets to unlock new sources of value

  • Partnerships

    Leveraging our network of trusted partners to amplify the outcomes we deliver for our clients

  • Platform Strategy

    Create adaptable technology platforms that move with your business strategy

  • Back
  • Close   ✕
  • Go to overview
  • Automotive
  • Cleantech, Energy and Utilities
  • Financial Services and Insurance
  • Healthcare
  • Media and Publishing
  • Not-for-profit
  • Public Sector
  • Retail and E-commerce
  • Travel and Transport
  • Back
  • Close   ✕
  • Go to overview
  • Featured

  • Technology

    An in-depth exploration of enterprise technology and engineering excellence

  • Business

    Keep up to date with the latest business and industry insights for digital leaders

  • Culture

    The place for career-building content and tips, and our view on social justice and inclusivity

  • Digital Publications and Tools

  • Technology Radar

    An opinionated guide to technology frontiers

  • Perspectives

    A publication for digital leaders

  • Digital Fluency Model

    A model for prioritizing the digital capabilities needed to navigate uncertainty

  • Decoder

    The business execs' A-Z guide to technology

  • All Insights

  • Articles

    Expert insights to help your business grow

  • Blogs

    Personal perspectives from ThoughtWorkers around the globe

  • Books

    Explore our extensive library

  • Podcasts

    Captivating conversations on the latest in business and tech

  • Back
  • Close   ✕
  • Go to overview
  • Application process

    What to expect as you interview with us

  • Grads and career changers

    Start your tech career on the right foot

  • Search jobs

    Find open positions in your region

  • Stay connected

    Sign up for our monthly newsletter

  • Back
  • Close   ✕
  • Go to overview
  • Conferences and Events
  • Diversity and Inclusion
  • News
  • Open Source
  • Our Leaders
  • Social Change
Blogs
Select a topic
View all topicsClose
Technology 
Agile Project Management Cloud Continuous Delivery  Data Science & Engineering Defending the Free Internet Evolutionary Architecture Experience Design IoT Languages, Tools & Frameworks Legacy Modernization Machine Learning & Artificial Intelligence Microservices Platforms Security Software Testing Technology Strategy 
Business 
Financial Services Global Health Innovation Retail  Transformation 
Careers 
Career Hacks Diversity & Inclusion Social Change 
Blogs

Topics

Choose a topic
  • Technology
    Technology
  • Technology Overview
  • Agile Project Management
  • Cloud
  • Continuous Delivery
  • Data Science & Engineering
  • Defending the Free Internet
  • Evolutionary Architecture
  • Experience Design
  • IoT
  • Languages, Tools & Frameworks
  • Legacy Modernization
  • Machine Learning & Artificial Intelligence
  • Microservices
  • Platforms
  • Security
  • Software Testing
  • Technology Strategy
  • Business
    Business
  • Business Overview
  • Financial Services
  • Global Health
  • Innovation
  • Retail
  • Transformation
  • Careers
    Careers
  • Careers Overview
  • Career Hacks
  • Diversity & Inclusion
  • Social Change
Languages, Tools & FrameworksTechnology

Pre-commit: Don’t git hooked!

 Matt Riley Matt Riley

Published: Jan 13, 2020

Git hooks are a feature of git that enable custom scripts to be triggered on certain events during the execution of a git command, such as pre-commit and pre-push. It’s common practice for teams to use git hooks to run quality checks to ensure they are run by all developers every time. While this is a good sign that a team cares about quality and repeatability, I observe that this practice has some major downsides. In this article, I’ll explore why, and what you might do instead.

​In order to maintain a stable build, teams practicing Continuous Integration gain confidence by running quality checks before committing or pushing to trunk (master). Examples include code formatting, linting, and unit testing.
 
We strike a balance between confidence and speed.

While the checks are valuable, they also take time to run. As a matter of practicality, we strike a balance between confidence and speed. This leads us to select the checks that provide the greatest confidence in the shortest time. In other words, we trade confidence for speed. The build serves as a safety net, and we stand ready to fix the build when it breaks.

Remembering to run the checks can take some discipline so it’s no wonder that git hooks are used as guardrails to ensure it.

But what if you are disciplined? What if you literally just ran the checks out of discipline, only to be forced to wait for them to run again on the pre-commit hook? What if you’re practising test-driven development (TDD) and have developed a habit of small and frequent commits? Unless the checks are really fast, that kind of wait time is enough to be distracted, break the developer experience, and impede productivity.
 
​The pre-commit hook would re-run the very same checks we literally just ran!

I was recently pairing with a colleague and we were ready to commit about once every 10 minutes. We were running the quality checks regularly out of habit, and each run took about about 2½ minutes. That’s a long time! Upon success, we’d commit and push. The pre-commit hook would re-run the very same checks we literally just ran! These may not sound like big numbers, but consider that for every 10 minutes of development, at least 5 additional minutes were spent running checks. That’s 50% of the development time! On a more positive note, the wait time enabled us to get to know each other a little better, although the checks had well and truly completed by the time we refocused our attention.
 
​​The pre-commit experience needs to be fast and frictionless to encourage the behaviours needed to achieve Continuous Integration.
 
Git hooks used in this way are a sign of a team that cares about quality. This is a good thing. However it’s also important to note that when developers feel impeded, they will find a workaround. When developers start delaying commits, increasing the size of commits, or batching commits to defer pushing their changes, we are losing ground. Continuous Integration is about minimising the time any change is isolated from any other change. The pre-commit experience needs to be fast and frictionless to encourage the behaviours needed to achieve Continuous Integration.

Person pointing at a laptop screen.

You may be wondering whether the pre-push hook would be more appropriate than the pre-commit hook, with the thought being that we could batch commits and defer running the checks until we’re ready to push. My question to you would be, why are you not pushing every commit? Doesn’t the thought of making a series of potentially broken commits until “the last one” make you feel slightly uncomfortable? How long are you actually holding onto those changes? Are you actually practising Continuous Integration by pushing your changes to trunk many times per day? Good commits are small, specific, and tested. Test-driven development inherently yields commits of this quality.
 
​​​Is it possible that being so preventative is actually encouraging behaviours that impede productivity?

Of course you could just bypass the hooks altogether with --no-verify. Does the thought of this make you feel guilty? Are you scared of breaking the build? Does your team believe the build should always be green? Does your team have a culture of shaming broken builds? If this sounds like your team, take a step back and ask why. Is it possible that being so preventative is actually encouraging behaviours that impede productivity? Have you got the balance right?
 
​Ironically, the discipline of maintaining a stable build is gained through the experience of breaking the build.

What about the so-called junior developers in the team? You know—the ones who aren’t so disciplined? Aren’t hooks a good way to ensure they’ve run the checks? Maybe. But at the end of the day, we want developers to run the checks because they’ve come to understand and value them, not blindly because some guardrail enforced them. Ironically, the discipline of maintaining a stable build is gained through the experience of breaking the build.

While git hooks are a compelling guardrail to help enforce quality, like any guardrail, they also come with some downsides including slowing down well-disciplined developers, and withholding opportunities for less-disciplined developers to gain that discipline.

Consider the following ideas to improve discipline and reduce reliance on git hooks as guardrails in your team:
  • Make the quality checks really fast. Like 10 seconds fast! The faster they are, the more likely they are to be run frequently, or ideally, continuously.
     
  • Practise test-driven development. The small increments driven by the red-green-refactor cycle demand fast-feedback. The pain felt experiencing slow-feedback during TDD should create incentive to make the quality checks faster.
     
  • Practise continuous integration with trunk-based development. The small increments driven by frequent (many times per day) and stable commits to trunk demand fast-feedback.
     
  • Commit frequently and push every commit. Small increments demand fast-feedback. The “test && commit || revert” approach helps to encourage this kind of workflow.
     
  • Practise pair programming. Pairing is a great way to learn practices like TDD and helps improve discipline by encouraging good behaviour between each other.
     
  • Be very selective about what to include in the quality checks to keep them fast. This might mean choosing not to run the end-to-end tests for example. It’s great to have the ability to run the entire pipeline locally, but avoid enforcing it to be run during pre-commit.
     
  • Consider that tech choices including languages and tools often have a direct impact on the speed of the checks. For all their benefits, compiled languages (e.g. C#, Java, Scala), transpilers (e.g. TypeScript), and containers (Docker), for example, come at the cost of taking longer to run. Be critical about balancing the pros and cons of these choices.
     
  • Don’t shame broken builds. See a broken build as an opportunity to build discipline by allowing the team to feel the impact and learn from the experience.
     
  • Remember that the build is your safety net. Keeping the build stable does not mean preventing the build from ever breaking, but stand ready to fix the build when it does break.​
Disciplined teams can avoid the overhead of guardrails when team members understand and come to value good practices. Rather than focusing effort into guardrails to prevent developers doing the “wrong thing”, focus on building discipline so that developers will learn to do the “right thing”.

Technology Hub

An in-depth exploration of enterprise technology and engineering excellence.

Explore
Related blogs
Software Testing

Test Driven Development is the best thing that has happened to software design

Arek Torczuk
Learn more
Languages, Tools & Frameworks

How programming languages have evolved

Rebecca Parsons
Learn more
Software Testing

The origin of Smoke Testing and the confusion it can cause

Aiko Klostermann
Learn more
  • What we do
  • Who we work with
  • Insights
  • Careers
  • About
  • Contact

WeChat

×
QR code to ThoughtWorks China WeChat subscription account

Media and analyst relations | Privacy policy | Modern Slavery statement ThoughtWorks| Accessibility | © 2021 ThoughtWorks, Inc.