main branches locally
main branches locally
Posted Oct 24, 2025 1:44 UTC (Fri) by mathstuf (subscriber, #69389)In reply to: main branches locally by gioele
Parent article: Git considers SHA-256, Rust, LLMs, and more
If upstream ever rewrites history, the `ff-only` can leave you stranded. I prefer to just always trust what the remote repo is. Granted, actual rewriting should be for *extreme* cases (e.g., legal in nature or catastrophic like "oops, committed my VM disk"), but I see no reason to force ff-only here.
> 2) ignore all branches of $UPSTREAM-REPO not pointed by HEAD (so, only fetch `main`),
Some projects have support branches (`release` or the like). I also like to have these. It's the main reason I prefer upstream repos to only publish their maintained branches.
> 3) prevent direct pushes to $UPSTREAM-REPO (I may have admin access to that repo, but our workflow is PR-based),
> 4) block commits to the `main` branch (all development should happen in feature branches).
Branch protection rules (i.e., server-side git hooks) should handle these situations. There's nothing to be done on the developer's side for these as I want the server to enforce them.
> I know that there are plenty of situations in which this kind of arrangement would not work, but it would cover the vast majority (95%+) of the projects and repos I deal with.
Yes, but when you bake in policy, all those corner cases become much sharper. Personally, I have a `git gh-add-fork` command that adds a fork on github to a repo I have with a structured name (`gh/$handle`) and, if it is my handle, sets it as the `remote.pushdefault` as well.
