1

I have a shell script that runs over a Git repository, and it compares the current branch to the default branch.

Right now it's hard-coded to master, but I need it to be dynamic to whatever the default/main branch of the repo is.

Is there a command to get the default branch of a repo, without using the GitHub API?

Asocia
  • 5,935
  • 2
  • 21
  • 46
jlouzado
  • 442
  • 3
  • 17
  • There is no "default" branch. (The default *name* of the initial branch is "master", though.) – mkrieger1 Jan 28 '21 at 16:07
  • default in the sense, that when you make a PR it's the default branch that it's made against. I'm aware that that's a github/gitlab concept, I'm trying to figure out if there's anything that denotes a branch as being the "main" one. – jlouzado Jan 28 '21 at 16:09
  • https://stackoverflow.com/search?q=%5Bgithub-api%5D+default+branch – phd Jan 28 '21 at 16:14
  • 1
    the closest answer I could find is here, and doesn't require the API https://stackoverflow.com/a/64795507/3121906 – jlouzado Jan 28 '21 at 16:18
  • 2
    That's not reliable, however: https://stackoverflow.com/questions/28666357/git-how-to-get-default-branch#comment95550167_44750379 – mkrieger1 Jan 28 '21 at 16:21
  • Why without using the GitHub API? – ChrisGPT was on strike Jan 28 '21 at 22:37

0 Answers0