What is the point to namespaces in branches in git?

So I mainly use Mercurial for my projects and I decided to sit down and learn all Git’s shenanigans to discover if I’m in the right side (at least for me).

I’m learning that git uses namespaces for branches and I would like to know (in your experience) what is the point of namespaces?. In Mercurial I could just set the convention of naming branches like so:

<branch name> //for "origin" branches
<username>/<branch name> //for user branches

I imagine that there is more to it than just the name (aside from avoiding naming conflicts), but what do I get out of this seemingly more complicated (not necessarily bad) model?

Git doesn’t “use” namespaces in the sense like they are required. It offers the completely optional ability for a user to use namespaces if they want them. You can use the exact same naming convention as you did in mercurial if you want, and I imagine that’s what the vast majority of people do.

What namespaces buy you is the ability to combine multiple repositories into one, but be able to only show branches from the one virtual repository. Within the namespace, you can still name the branches using whatever method you prefer. Personally, I don’t really see the benefit over just using multiple repositories, but obviously someone thought it might be useful sometimes.

Git has a ton of features, of which maybe 3-5% see daily usage by the typical developer. The trick to getting along with git, is for those features you don’t want/like/understand, don’t worry about them.

Git doesn’t use namespaces for branches.

A legal Git ref (like a branch) is allowed to look like a filepath as
seen on Unix systems like Linux, which means that e.g.:

  • feature/xyz is allowed
  • feature/zzz/subtask1

Are legal refs.

While these are not:

  • /
  • feature//zxy

So you may use this permissible syntax to implement informal
“namespaces”. If you want. But it’s not some kind of feature.[1]

All you have to keep in mind that if you create a branch like:

  • test/featurex

Then you can never create a branch named test:

$ git co -b test
fatal: cannot lock ref 'refs/heads/test': 'refs/heads/test/featurex' exists; cannot create 'refs/heads/test'

Just like you couldn’t create a directory test and also a regular file
test in the same directory.

Example

The current Git maintainer uses the prefix <initials>/ for all topic
branches in his repo. For example (fetched today, 2023-04-16):

ab/avoid-losing-exit-codes-in-tests
ab/bisect-cleanup
ab/bundle-wo-args
ab/cache-api-cleanup
ab/cache-api-cleanup-users
[snip]
cw/ci-whitespace
cw/doc-pushurl-vs-url
[snip]

Note: don’t confuse this with gitnamespaces

Don’t confuse this “namespace” branching practice with gitnamespaces
which apparently[2] allows a single (remote/server) repository to be
used to serve refs from multiple repositories (because the refs are
stored under refs/namespaces/[…]):

Git supports dividing the refs of a single repository into multiple
namespaces, each of which has its own branches, tags, and HEAD. Git
can expose each namespace as an independent repository to pull from
and push to, while sharing the object store, and exposing all the refs
to operations such as git-gc(1).

Notes

  1. And you may as well use --, & or whatever else (legal character)
    as the “namespace separator”. But / does look nicer. 😉
  2. man gitnamespaces, Git 2.40.0

Never done something serious with mercurial, so I can miss something.
I’m using namespaces in git branch naming pretty much, but I’m never inserting my name into the name of the branch.

For each task that are describe in task tracker we are creating a separate branch, with number of the ticket and short description of the bug. At this point there are no spaces yet:

  remotes/origin/275-test-new-urls
  remotes/origin/283-fullscreen
  remotes/origin/299-current-menu-item
  remotes/origin/301-users-api
  remotes/origin/306-range-window-resize
  remotes/origin/307-dropdown-init-onload

Then, say, you realize that some task need additional branches for experimenting. These branches are de-facto children to “main” task branch, i.e. after completion the should (if should at all) be merged to that very task. Here come namespaces:

 remotes/origin/283-fullscreen-buggy-animation   
 remotes/origin/283-fullscreen.refactor

I’ve seen that slash is also used for namespacing, but personally I prefer dots, since using slashes can produce some issues.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật