1

Often master is the base branch but not always. Is there a git command that can tell me the name of the base branch? I want to use this to make some git aliases for commands that need to know the base branch name and I want these aliases to be useful across repositories where the base branch may differ.

ryanve
  • 50,076
  • 30
  • 102
  • 137
  • Have you tried this - https://stackoverflow.com/questions/28666357/git-how-to-get-default-branch – Vandesh Jul 31 '17 at 21:43
  • Git does not really have the concept of a "base" branch. Branches are all independent: they're just pointers, pointing to one specific commit. Each branch name *can* have one (at most, or zero is the other option) *upstream* setting but typically those are remote-tracking names: the upstream for `master` is `origin/master`, and so on. – torek Jul 31 '17 at 21:45

1 Answers1

2

"Base branch" -> This isn't actually a git construct. There is no such thing as a "base branch" in git.

There is such a thing as a default branch for bitbucket or github, though. The best way to figure this out might be to use e.g. github's REST API to figure that out. cURLing https://api.github.com/repos/djhaskin987/degasolv would, for example, return a JSON object with default_branch field in it giving that repo's default branch of develop.

If you're just cloning a generic git repository though, it seems that whatever is in HEAD will be checked out when that git repo is cloned.

djhaskin987
  • 9,741
  • 4
  • 50
  • 86