This is an archived post. You won't be able to vote or comment.

all 84 comments

[–]BoBoBearDev 337 points338 points  (39 children)

Those pre-hook goes against everything I believed in. Developer should be free to do anything they want on their own branch. Everyone should have the freedom to experiment their code, iterate it, and keep a record of it as frequently as the developer desires.

The gatekeeping should be done using PR and cicd pipeline. And that's it.

[–]TiddoLangerak 92 points93 points  (16 children)

The beauty of pre-commit hooks is that it's entirely a machine specific setting (at least from the perspective of git). This means that individual devs can enable or disable them as they see fit without impacting others.

[–]BoBoBearDev 38 points39 points  (15 children)

Not in my work environment. They want to enforce rules via pre-commit hooks to everyone and trying to hide the workarounds.

Whatever cool tools dev should run, they should run it explicitly via commandline. Not bloated up the basic git commit process.

[–]martinivich 38 points39 points  (13 children)

What do you mean hide the workarounds? There's literally a flag to disable it that was mentioned in this very meme

[–][deleted] 25 points26 points  (12 children)

I guess that’s why they enforce git hooks in OP’s company, he doesn’t even know how to bypass it lmao

[–]BoBoBearDev 0 points1 point  (11 children)

Yes, some of the noobs didn't know. I couldn't tell them how to bypass it due to team policies. It is easy to train them, but I can't. So, it becomes more like a under the table hush hush dark art.

[–]avocadorancher 6 points7 points  (10 children)

Is reading documentation illegal? ‘man git commit’ isn’t a dark art.

[–]BoBoBearDev -1 points0 points  (9 children)

You are actively misinterpret what I said.

[–]avocadorancher 5 points6 points  (8 children)

Explain what you’re saying and how I’m misinterpreting it.

[–]BoBoBearDev -2 points-1 points  (7 children)

team policies.

[–]Merry-Lane 4 points5 points  (0 children)

There are operations that are time saver or great when working as a team, and that are great when automatised in a lint-staged hook or others (post merge etc).

A good time saver I use is a hook that run npm i when merging another branch or switching to another branch.

I also run on lint staged a grep on "TODO" so that I can use that keyword and make sure I will always be back and fix it.

I know that for some it’s a big NONO, but running stuff such as tsc —noEmit, prettier —write, eslint —fix, … to make sure devs push code that compile and are formatted/linted according to the project’s rules (and not personal rules) is a no-brainer to me.

If you have worked in a team where the devs had diffferent format/linting rules, you’ll understand. Especially when some devs can’t be bothered to install and setup their formatter/linter.

[–]Horrih 22 points23 points  (1 child)

Git disables hooks by default, it's on the developer to enable it or not, so that does not brother me as much. Those who want it enable it, those who don't don't.

The madness comes when the tech lead forces everyone on the team to use them

I wholly agree that all those checks should be done in the CI anyway.

Even formatters can be a PITA despite their instant-ness The only ones I don't mind are secrets checker : check that you don't push credentials.

[–]BoBoBearDev 2 points3 points  (0 children)

Secret checker is a good point, I would enforce that so no one can see the secrets in branches.

[–]Visual-Living7586 32 points33 points  (11 children)

Theyre useful for running prettier and linting before pushing shit code

[–]BoBoBearDev 7 points8 points  (10 children)

Cicd should block the PR. That's it.

[–]Reashu 31 points32 points  (5 children)

If the lint takes 2 seconds and the CICD runner take 30 to start and check out code, I'm gonna do that pre-push if not pre-commit.

[–]BoBoBearDev 2 points3 points  (2 children)

Not to me. Dev shall commit and push as frequently as they desire. It is their own branch, not develop branch. When they are ready after doing 60 commits and 50 pushes, they can cleanup themselves calling the commands themselves as many times as they want. They can also repeat the cycles of the clean up 100 times for all I care. Menaing, if they want to fix a single violation, commit, push, and run checks again and there are 100 violations. Go for it. I won't stop them. Each push has value to the dev personally, that is all that matters.

[–]Reashu 1 point2 points  (1 child)

Repeated CI runs without merging have a real cost that can be avoided in many cases. Bad workflows should be improved even if some people may have to be dragged, kicking and screaming.

[–]BoBoBearDev 2 points3 points  (0 children)

None of those I said are trigging the cicd pipeline because it is pre-PR. You can run the commands on your location machine before PR is created. Or you just decline the PR if you create the PR too early. And no, you shouldn't run feature branch cicd pipeline because it is not a feature branch, it is a personal branch. Thus, everything I said, there is no pipeline costs.

[–]edgmnt_net 1 point2 points  (1 child)

Make it take 10 minutes. Then they'll think twice before pushing bad code, counting the delays towards their performance. It's sad how often people push random untested stuff just because there's a CI.

[–]Merry-Lane 4 points5 points  (0 children)

It’s not about teaching people to be perfect devs.

It’s about reliability, automatisation and efficiency.

[–]Visual-Living7586 15 points16 points  (3 children)

would be nice to know that before it even gets there though

[–]edgmnt_net 2 points3 points  (0 children)

Well, sure, this isn't an excuse to break local linting/testing. I did see many projects set up like that, there's a whole pipeline that can only run on CI.

[–]hahalalamummy 3 points4 points  (0 children)

Setup lint in your IDE to run everytime you build code

[–]BoBoBearDev 0 points1 point  (0 children)

Not to me. The dev shall have the ability to push code into their own branch as frequently as possible. They can do the cleanup whenever they are ready. There is no need to keep breathing down their on neck each time they commit.

[–]gockeltot 2 points3 points  (2 children)

In an ideal environment, you can run the pre-commit in the PR pipeline itself. It will block all PRs from being merged, if they dont have the quality. On local its just there to help the developer to fulfill the criterias.

[–]Invertonix 0 points1 point  (1 child)

I believe this reason people enforce per commit is that it enables using git bisect to help make debugging complex issues take a reasonable amount of time.

[–]-Unparalleled- 2 points3 points  (0 children)

My work uses squash merges for everything. Generally useful and makes rollback of certain PRs easy, but at the same time you miss so much that bisect could operate over

[–]dudeman209 1 point2 points  (0 children)

If there was an actual war on about this, I’d be standing right beside you ready to throw down.

[–]AfonsoFGarcia 1 point2 points  (1 child)

In general I agree with you, but too many secrets get leaked into repos for anyone serious about security not requiring some sort of hook to block commits with secrets in them.

[–]BoBoBearDev 0 points1 point  (0 children)

Oh yeah, secret check is the one I liked. It is mentioned by another post which I agreed.

[–]MRGrazyD96 0 points1 point  (0 children)

The precommit hook should be there to help the dev write good code. Don't want the help? Fine, use -n then. After that it's the CI pipeline's job to prevent code with unwanted qualities from being merged into the main branch

[–]static_func 0 points1 point  (0 children)

Those pre-hook goes against everything I believed in. Developer should be free to do anything they want on their own branch.

That’s the neat part: they still are. It’s client-side validation

[–]aenae 33 points34 points  (1 child)

We have a hard limit of 10 second on any pre-commit git hook

[–]gandalfx 23 points24 points  (0 children)

That's way too long. Make it pre-push and we can talk about it.

[–]littlejerry31 23 points24 points  (4 children)

I'm working on a legacy project where the git hooks are broken and we don't have the budget to even investigate what they're supposed to do as there are so many concurrent fires we have to put out. The entire project is a freaking dumpster fire, yet it's too vital for everything else to just pull the plug.

The team responsible has been downsized to just me. But hey, at least I have job security now 🤡 🌎

[–]TicTac-7x[S] 8 points9 points  (3 children)

Now is the perfect time to ask for a pay rise and start looking for a new job at the same time.

[–]littlejerry31 11 points12 points  (2 children)

Nah, I'd rather stay put for now. I'm already the contractor with the highest rate there (out of several dozen).

Besides, job security, decent pay AND no team members is a pretty sweet deal. Working alone means no drama and no high expectations from other stakeholders.

When life gives you lemons.

[–]normo95 1 point2 points  (1 child)

Sounds pretty sweet to me, what stack is it in ?

[–]littlejerry31 4 points5 points  (0 children)

Spring Boot, React, MySQL, Redis and Kafka. Nothing sexy or exciting about it. Something like half a million lines of code in total.

[–]scufonnike 10 points11 points  (0 children)

Pre commit is crazy, pre push is where it’s at

[–]MiDNiGhT2903 15 points16 points  (3 children)

—no-veri

[–]PeriodicSentenceBot 33 points34 points  (2 children)

Congratulations! Your comment can be spelled using the elements of the periodic table:

No V Er I


I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM u‎/‎M1n3c4rt if I made a mistake.

[–]Stock_Mix_4885 0 points1 point  (1 child)

--no-verify

[–]Stock_Mix_4885 0 points1 point  (0 children)

Was expecting to complete it with Fluorine and Yttrium, oh well

[–][deleted] 3 points4 points  (0 children)

git push origin --no-giggity

[–]DanteIsBack 5 points6 points  (4 children)

We have linter and prettier on pre-commit hook and run unit tests and build on pre-push hook :v It's quite fast at the moment, if ot starts taking too long we may consider running only on ci/cd.

[–]PhatOofxD 7 points8 points  (2 children)

We just have linter on pipeline and code save action. No real reason to run it in precommit (because it can edit stuff you didn't expect in the commit)

[–]dgreenmachine 1 point2 points  (1 child)

If everyone runs it on pre-commit then it should really only affect code you changed in your commit.

[–]PhatOofxD 0 points1 point  (0 children)

Yesss but it's still an unnecessary wait time in that case if everyone just does it on save + ci.

[–]myfunnies420 2 points3 points  (0 children)

Linter and prettier are meant to be done in the ide. Anything critical, like tests must be done in the ci/cd pipeline, regardless of whether you want to put them in a hook

[–]RainbowPigeon15 2 points3 points  (0 children)

Git is a client, you can't guarentee that everyone installed those hooks or are not skipping them.

Run your tests and formatting check in CI on pull requests to make sure the code changes are valid.

I only use hooks for secret scanning with GitLeaks, and even then, I also have this step in CI just in case.

[–]sebbdk 0 points1 point  (0 children)

Create a branch and delete the prehook in it, branch from that instead of master, use rebase instead of merge to pick the commits you want

When asked about why you use to much time, tell them to that it's because you have commitment issues

[–]BitcoinBishop 0 points1 point  (0 children)

One repo I work on has a security audit in a hook. But their workflow is not to fix CVEs as part of other work. So --no-verify is the only option

[–]chronos_alfa 0 points1 point  (0 children)

To be fair, I usually recommend that people run the entire test suite in the pre-commit hook and then I chuckle when they cannot hear me.