ryanve
ryanve

Reputation: 52501

git command to get name of base branch

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.

Upvotes: 1

Views: 1221

Answers (1)

djhaskin987
djhaskin987

Reputation: 10057

"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.

Upvotes: 2

Related Questions