Master
ThoughtWorks
Menü
schließen
  • Unsere Services
    • Übersicht
    • Customer Experience, Produkt und Design
    • Data Strategy, Engineering und Analytics
    • Digitale Transformation und Operations
    • Enterprise Modernization, Plattformen und Cloud
  • Unsere Kunden
    • Übersicht
    • Automobil
    • Gesundheit
    • Öffentlicher Sektor
    • Clientech, Energie und Versorgung
    • Medien
    • Handel und E-Commerce
    • Banken und Versicherungen
    • Non-Profit
    • Reise und Transport
  • Insights
    • Übersicht
    • Unsere Empfehlungen

      • Technologie

        Ausführliche Betrachtungen neuer Technologien.

      • Business

        Aktuelle Business-Insights, Strategien und Impulse für digitale Querdenker.

      • Kultur

        Insights zu Karrieremöglichkeiten und unsere Sicht auf soziale Gerechtigkeit und Inklusivität.

    • Digitale Veröffentlichungen und Tools

      • Technology Radar

        Unser Leitfaden für aktuelle Technologietrends.

      • Perspectives

        Unsere Publikation für digitale Vordenker*innen

      • Digital Fluency Model

        Ein Modell zur Priorisierung digitaler Fähigkeiten, um für das Unvorhersehbare bereit zu sein.

      • Decoder

        Der Technology-Guide für Business Entscheider

    • Alle Insights

      • Artikel

        Expertenwissen für Ihr Unternehmen.

      • Blogs

        Persönliche Perspektiven von ThoughtWorkern aus aller Welt.

      • Bücher

        Stöbern Sie durch unsere umfangreiche Bibliothek.

      • Podcasts

        Spannende Gespräche über das Neueste aus Business und Technologie.

  • Karriere
    • Übersicht
    • Bewerbungsprozess

      Finde heraus, was dich in unserem Bewerbungsprozess erwartet.

    • Hochschulabsovent*innen und Quereinsteiger*innen

      Dein Einstieg in die IT-Welt.

    • Stellenangebote

      Finde offene Stellen in deiner Region.

    • In Kontakt bleiben

      Abonniere unsere monatlichen Updates.

  • Über uns
    • Übersicht
    • Unser Ziel
    • Awards und Auszeichnungen
    • Vielfalt, Gleichberechtigung, Inklusion
    • Management
    • Partnerschaften
    • Neuigkeiten
    • Konferenzen und Events
  • Kontakt
Germany | Deutsch
  • United States United States
    English
  • China China
    中文 | English
  • India India
    English
  • Canada Canada
    English
  • Singapore Singapore
    English
  • United Kingdom United Kingdom
    English
  • Australia Australia
    English
  • Germany Germany
    English | Deutsch
  • Brazil Brazil
    English | Português
  • Spain Spain
    English | Español
  • Global Global
    English
Blogs
Wählen Sie ein Thema
Alle Themen ansehenschließen
Technologie 
Agiles Projektmanagement Cloud Continuous Delivery  Data Science & Engineering Defending the Free Internet Evolutionäre Architekturen Experience Design IoT Sprachen, Tools & Frameworks Modernisierung bestehender Alt-Systeme Machine Learning & Artificial Intelligence Microservices Plattformen Sicherheit Software Testing Technologiestrategie 
Geschäft 
Financial Services Global Health Innovation Retail  Transformation 
Karriere 
Karriere Hacks Diversity und Inclusion Social Change 
Blogs

Themen

Thema auswählen
  • Technologie
    Technologie
  • Technologie Überblick
  • Agiles Projektmanagement
  • Cloud
  • Continuous Delivery
  • Data Science & Engineering
  • Defending the Free Internet
  • Evolutionäre Architekturen
  • Experience Design
  • IoT
  • Sprachen, Tools & Frameworks
  • Modernisierung bestehender Alt-Systeme
  • Machine Learning & Artificial Intelligence
  • Microservices
  • Plattformen
  • Sicherheit
  • Software Testing
  • Technologiestrategie
  • Geschäft
    Geschäft
  • Geschäft Überblick
  • Financial Services
  • Global Health
  • Innovation
  • Retail
  • Transformation
  • Karriere
    Karriere
  • Karriere Überblick
  • Karriere Hacks
  • Diversity und Inclusion
  • Social Change
Sprachen, Tools & FrameworksTechnologie

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
Weitere Blogposts
Software Testing

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

Arek Torczuk
Mehr hier
Sprachen, Tools & Frameworks

Die Entwicklung der Programmiersprachen

Rebecca Parsons
Mehr hier
Software Testing

The origin of Smoke Testing and the confusion it can cause

Aiko Klostermann
Mehr hier
Master
Datenschutz | Modern Slavery statement | Barrierefreies Webdesign
Connect with us
×

WeChat

QR code to ThoughtWorks China WeChat subscription account
© 2021 ThoughtWorks, Inc.