1

I want to know to which all branches contain a particular commit in a github.com repository. Suppose I need to list all branches which contain commit. I am aware of following ways:

  1. Swicth to each branch and see the last commit date and compare it with the commit's date. This is not feasible if there are multiple branches and tags.
  2. Checkout the github repo and do git branch --contains <commit> (related SO question). I would prefer not checking out the repo as I need to browse a large number of repos on a daily basis.

Both of these ways are time consuming. Is there a better way?

Saim Raza
  • 1,420
  • 13
  • 16
  • "*I need to browse a large number of repos on a daily basis*" Once you clone all the repos you just **update** them next time, not do a full clone again. Also you can script your local checks. – phd Nov 28 '19 at 10:00
  • 1
    Re method 2, don't forget the `-r` switch on `git branch --contains` (and `git fetch` first) – bcmcfc Nov 28 '19 at 11:15

1 Answers1

0

GitHub doesn't provide a way to do this in the API, so you'd need to clone the repository and do it yourself, as in your second proposed solution. Your first technique isn't effective in the general case because it doesn't indicate whether that commit is in a given branch, only whether a given branch is newer than a given commit.

Note that it is possible to crawl history slowly through the GitHub API, but it's slow enough that cloning is faster, and you'll get rate limited far before you're done with your task, which will further impede your progress.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Would it be worthwhile if a feature to do so is added to github? – Saim Raza Nov 29 '19 at 05:23
  • 1
    This is potentially an expensive operation if you have many branches and commits, so at a certain repository size, the operation would always time out. You're welcome to ask them for an API, but I expect that's the reason why they don't have one. – bk2204 Nov 29 '19 at 12:12