Can you help explain everything about branches with dev- in their name, what branch-alias mean, why they are needed, why this might have been used here and anything else you feel relevant as I find this all very confusing
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Absolutely! Let's walk through this step by step and explain everything related to branches, Composer conventions, and especially the "branch-alias" part in your composer.json.
🌿 TL;DR Summary (Before We Dive In)
dev-* branches are development branches in Git.
Composer uses dev-<branch> to install unstable versions directly from source.
"branch-alias" maps a branch name like dev-main to a version number like 4.x-dev.
This helps users require unstable versions using semantic versioning ("vendor/name": "4.x-dev").
It keeps compatibility with other packages that expect versioned dependencies.
📚 1. What Are dev-* Branches?
In Git, any branch starting with dev-, such as dev-main or dev-feature/xyz, is typically used for development work — not stable releases.
“Treat the dev-main branch as if it were version 4.x-dev.”
So now when someone writes:
json
"require": {
"you/yourpackage": "4.x-dev"
}
They're actually installing the latest code from the main branch.
🧠 Why Is This Needed?
Because Composer uses semantic versioning (1.0.0, 2.5.3, etc.) to manage dependencies. But when you're developing on a Git branch like main, Composer doesn’t know what version that represents.
By adding a branch alias:
You're telling Composer how to treat this branch in terms of version numbers.
Other packages can depend on "you/yourpackage": "^4.0" or "4.x-dev" without breaking.
And they’ll get your latest changes from the main branch.
When you release v4.0.0, Composer will switch to using that tagged version automatically.
📦 6. Bonus: Version Constraints Explained
Here’s how Composer interprets common constraints:
Constraint
Meaning
^4.0
Stable versions >= 4.0.0 < 5.0.0
~4.1
Stable versions >= 4.1.0 < 4.2.0
4.x-dev
Development branch mapped to version 4.x
dev-main
Raw branch name — installs from source
Using 4.x-dev is better than dev-main because:
It allows Composer to resolve version conflicts properly.
It gives more flexibility in dependency management.
🧼 7. Best Practices
Always use "branch-alias" for active development branches.
Avoid relying on dev-branchname unless you really need to.
Prefer semantic version tags (v4.0.0) for production/stable use.
Set "minimum-stability": "dev" only during development.
Use "prefer-stable": true to prioritize stable versions when possible.
📄 Final Thoughts
The key takeaway:
"branch-alias" makes development branches compatible with Composer's versioning system, allowing you to use development code safely in other projects while maintaining version compatibility.
If you're maintaining a package or a fork, this setup lets you share unstable features without breaking downstream applications.
Would you like me to show an example of how to create a new dev branch, set up its alias, and publish updates via GitHub?