this post was submitted on 27 Dec 2025
18 points (87.5% liked)

Git

4059 readers
10 users here now

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Resources

Rules

  1. Follow programming.dev rules
  2. Be excellent to each other, no hostility towards users for any reason
  3. No spam of tools/companies/advertisements. It’s OK to post your own stuff part of the time, but the primary use of the community should not be self-promotion.

Git Logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.

founded 2 years ago
MODERATORS
top 17 comments
sorted by: hot top controversial new old
[–] fruitycoder@sh.itjust.works 2 points 23 hours ago

Ehh each tool it's job. Wanted to agree but pre commit checks to keep secrets from entering the graph makes sense at every level for me. Anything that is too keep the git DB itself clean goes there. So if you have Conventional Commits standards precommit checks make sense. Checks for secrets. Tbh that's the furthest I've done for a precommit.

Pre push is a good place to start any orginzational checks though. Pipelines for tests and smell checks or anything fuzzy really (can normally be seen by maintainers in the merge requests). K8s (like fleet, argocd, etc) for ops checks (is this running, is the service accepting requests, etc).

[–] KissYagni@programming.dev 4 points 1 day ago (1 children)

Everytine I've seen a pre-commit hook in my job, it was something that should have been in integration pipeline.

You should not run linter, test or any static analysis tool in a pre-commit (I'm looking at you husky 😡). Why ? Because:

  • It takes time. A commit should be instantaneous.

  • It may change the content of the commit or of the repos without explicite action of the developer.

  • The developper's branch is the developper's mess. He don't have to respect any convention, any quality gate or any workflow on its branch. Quality gates should happen only when integrating into trunk.

I always commit and push on Friday afternoon before leaving as "WIP", in case my computer crash during week end. I don't want to address issues of a WIP job. I just want to backup my work.

I may commit several time per minute, and do a rebase latter. I don't want to spend 2min each time waiting for eslint to parse the repos. I don't want to fix styling because I now I will fix it later and rebase -i before pushing.

You can use custom pre-commit in your own workflow, but forcing all developer to have the same pre-commit is a bad idea.

[–] Michal@programming.dev 1 points 1 day ago (1 children)

Amen. I also need to be able to commit WIP quickly if i need to urgently checkout master, or push my code because my laptop battery is about to die and i dont want it to have the only copy of my work.

[–] TunaLobster@lemmy.world 3 points 1 day ago

There are ways to skip the hooks.

[–] falseWhite@programming.dev 4 points 2 days ago (2 children)

Never had any issues.

The article is just a sad dev ramble.

I don't know what's available for the Rust ecosystem, but for JS/TS someone already did all the hard work and it just works like magic. The library is called Husky.

[–] Michal@programming.dev 1 points 1 day ago (1 children)

Can you share what you use git commit hooks for?

[–] falseWhite@programming.dev 3 points 1 day ago* (last edited 1 day ago)

I run an eslint fix and prettier formatter. It's a typescript project.

[–] tyler@programming.dev 0 points 1 day ago (1 children)

husky has to be one of the most annoying and outright hostile libraries I've seen. Anytime I pull an open source project to get it working on my machine I have to go through and set up an entire development pipeline just to make a code change even if I never intend on upstreaming that change because husky forces formatting on commits. What an idiotic thing to do. The article covers this clearly. It's just not something that should be done on commit.

[–] falseWhite@programming.dev 2 points 23 hours ago

Wow. How difficult is it to add --no-verify or simply -n flag to skip the pre-commit hooks?

[–] Hyperlynx@aus.social 6 points 2 days ago (2 children)

@codeinabox I've got one to ask if I'm sure when I'm committing to anything called master or main. Helps prevent working in the wrong branch.

I don't need to only catch that at the push stage and then have to rebase 🤷🏻‍♂️

[–] JackbyDev@programming.dev 2 points 1 day ago

Actually rebasing before pushing is the best time to do so, so a pre-push hook seems great. You can also have your branch displayed in your shell which would help avoid this.

[–] Vulwsztyn@programming.dev 2 points 2 days ago* (last edited 2 days ago) (1 children)

you don't have to rebase.

create a new branch from main

push it

go to main

git reset --hard origin/main

[–] Hyperlynx@aus.social 3 points 2 days ago* (last edited 2 days ago) (1 children)

@Vulwsztyn yeah, "there are multiple ways to fix a mistake" is not the point, dude!

Besides which, yes I do have to rebase if I already have a topic branch for what I'm working on, and didn't pay attention to which branch I'm on.

I almost never want to commit to the main branch, only merge from a topic branch. So that means that having confirmation before committing to it is useful.

[–] JackbyDev@programming.dev 0 points 1 day ago (1 children)
git switch -c blah
git push -u origin blah
git switch main
git reset --hard origin/main
[–] Hyperlynx@aus.social 1 points 15 hours ago* (last edited 15 hours ago) (1 children)

@JackbyDev yes, friend, you too have entirely missed the point.

I have my branch displayed in my shell, but mistakes happen. And a pre-commit hook that checks what branch I'm on is an excellent way to avoid those mistakes.

I already have a topic branch, likely with a half a dozen odd commits in, which I intended to make my changes in. The hook avoids a mistake made on the one branch I know I pretty much never want to commit to directly.

Yes, I could continue making commits to the wrong branch, and then fix my mistake later. That's noooot the point! I want to commit to the right branch in the first place. Yes, I'm going to need to rebase eventually before I push and put up a merge request - also not the point. The point of the topic branch is that all my work in progress commits are there, I can see the history of what I've tried that has and hasn't worked, and then eventually clean it up with a rebase before actual submission.

All the work neds to go in the topic branch, always, and it already exists because I opened it as soon as I started work on that ticket.

[–] JackbyDev@programming.dev 1 points 14 hours ago (1 children)

I'm confused how this even happens. You switch to dev and then choose to keep working on your ticket, but your previous work isn't there, so how do you keep progressing? I can see this as an edge case, but it happens to you often enough that a pre commit hook is useful to stop it?

To be clear, I don't care what you do, if it works, it works, I just am having a difficult time understanding how this particular scenario happened enough that a pre commit hook was the best way to solve it.

[–] Hyperlynx@aus.social 1 points 14 hours ago

@JackbyDev well, it doesn't happen very frequently, it's more of a nice-to have.

It's more of an issue because our product has a lot of totally separate sections, as well as a separate companion app. It's easy enough to work on an issue without ever touching code affected by another, and for whatever reason have two or three issues in progress, each in their own branch.

Say, some task you're blocked on, in the meantime some minor issue from five years ago that nobody really cares about that much but would be nice, and then some other unrelated cleanup task as well.

But, even when I used to work at a place where there was only one single-purpose app, I still worked in topic branches and never ever wanted to actually commit to main (through the mistake was less likely to happen, I grant).