Hacker News new | past | comments | ask | show | jobs | submit login

> as far as I understand, local repos don't have a concept of a "main branch"

    $ git init
    Initialized empty Git repository in...
    $ git symbolic-ref --short HEAD
    main
    $ git switch --create feature-branch
    Switched to a new branch 'feature-branch'
    $ git switch ???
> You can resolve to which branch <remote>/HEAD points?

Correct, this is the best way I've found. I have this as a git-alias:

    main-branch = !basename $(git symbolic-ref refs/remotes/origin/HEAD)
But it doesn't help for local repositories that don't have a remote. And it's ironic to need to use "origin" for that, which is itself a "master/main"-like default remote name.



that's what I mean: "main" is just the automatically created branch so that there is a branch for HEAD to point to in an empty repo. It's not special in any functional way locally. I.e. if I create "develop" and delete "main", locally nothing in git itself will ever miss "main" or needs to be told that "develop" is the primary branch, because that's not a concept locally (afaik). It knows the current branch (HEAD), that's it. So wanting to look it up locally doesn't make sense from gits perspective, although maybe the ability to tag a branch as such would be useful for some tooling, but it would in a way introduce the concept to git, not expose something it hides now.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: