Skip to main content
Software Engineering

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

When is it acceptable to commit directly to main/master?

Working with Git, I’ve often heard that committing directly to the main (or master) branch is generally discouraged. Instead, many teams adopt workflows where all changes are made in separate branches, reviewed via pull requests, and then merged into main. In fact in my last job, it was company policy to ALWAYS branch, with no exceptions.

But is this always necessary? Are there situations where committing directly to main is acceptable, or even preferable? And if there are,how can the risks best be mitigated?

Answer*

Draft saved
Draft discarded
Cancel
8
  • 16
    I would also include "when you are the lone wolf" in this answer. If you are the only person working on the project, then you are the only one to suffer when something goes wrong. Personal projects (which are just a variant of "the lone wolf project") are another example where you can just commit and push to main. But in a team environment, trunk-based development is the only way to do this without causing chaos on a daily basis. Commented Dec 6, 2024 at 22:13
  • 1
    I have been a "lone wolf" rarely and being the only one who suffers is little consolation. I’d rather spend a bit of extra time and be on the safe side. Plus working on several items at the same time (some feature, a bug fix, a more urgent bug fix) means I act in several roles. Commented Dec 6, 2024 at 22:54
  • @GregBurghardt I don't believe that lone wolf or personal projects mean that you shouldn't have at least some of the safeguards that make it safe to commit to main possible. There's no reason to not have fast automated tests, good test coverage, and a pipeline. The only thing that you will probably skip is peer review, since you may not have peers to review the work with regularly. Commented Dec 6, 2024 at 23:32
  • even TBD uses branches Commented Dec 7, 2024 at 8:56
  • 2
    @Ewan Except...it doesn't. It almost never uses branches. Commented Dec 8, 2024 at 10:56

AltStyle によって変換されたページ (->オリジナル) /