I'd say you simply have to ask developers to namespace their branches
properly and don't step on each other; once there is a branch named
foo, one cannot anymore create a branch foo/bar, and vice versa.
The problem is not asking but more on the enforcing part specially when developers
are able to use this workflow outside bitbake without any issues.
Another upstream branch creation flow that triggers the fetch issue that doesn't
involve to explicitly set the branch in the recipe (as the first example that I provided):
- bitbake <recipe> -c do_fetch --no-setscene with branch "main" and SRCREV = aaa
- Created upstream branch "foo"
- bitbake <recipe> -c do_fetch --no-setscene with branch "main" and SRCREV = bbb (to double confirm that it fetch all the references upstream)
- Deleted upstream branch "foo"
- Created upstream branch "foo/bar"
- bitbake <recipe> -c do_fetch --no-setscene with branch "main" and SRCREV = ccc (to double confirm that it fetch all the references upstream)
- Fetch failed with error: cannot lock ref 'refs/heads/foo/bar': 'refs/heads/foo' exists; cannot create 'refs/heads/foo/bar'
A developer can create a upstream temporary branch and trigger this even if they are not aware of the issue.