1

Related to git - how to get default branch?

I'm trying to port a Bash script to Ruby. The script uses git symbolic-ref --short HEAD to get a repo's default branch.

Is there a way to combine rugged's repo.branches.each_name(:local) with some other command to find the default branch?

Or am I thinking too complicated and there is a useful default in rugged that I am missing? The script needs to continue by creating a new branch off the default/latest one, check-it out, commit something standardized, push the new branch, and open a pull request against that base branch.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Katrin Leinweber
  • 1,316
  • 13
  • 33
  • 1
    How exactly does `git branch --list | head -1 | sed -E 's/ *//'` get the *default* branch? It only returns the first branch from the list of branches. – Arkadiusz Drabczyk Dec 29 '18 at 13:22
  • https://stackoverflow.com/questions/28666357/git-how-to-get-default-branch – phd Dec 29 '18 at 14:16
  • `git symbolic-ref --short HEAD` – phd Dec 29 '18 at 14:16
  • @ArkadiuszDrabczyk: I guessed that the list had the HEAD branch on top. In my use so far, this worked, also when the default branch on GitHub was called `dev` or `src`. – Katrin Leinweber Dec 29 '18 at 19:40
  • I explicitly that Q already, see the Linked section to the top right of this ;-) I'll add that suggestion to the Bash script, but the point of this question is how to port that behaviour to Ruby. – Katrin Leinweber Dec 29 '18 at 19:41
  • Sorry but I still don't understand what *deafult* branch means to you - is it a) currently checked-out branch b) branch is automatically checked-out after cloning the repository? – Arkadiusz Drabczyk Dec 29 '18 at 19:51
  • The one that is specified in GitHub under `/settings/branches`, because repo owners often request PRs to be submitted against that one. If `git clone --depth=…` clones that one by default, the problem is already solved. – Katrin Leinweber Dec 30 '18 at 11:10

0 Answers0