Go here: https://github.com/search and enter "pattern repo:user_name/repo_name".
For example, to search for cnn_learner
in the fastai
repo of user fastai
, enter this:
cnn_learner repo:fastai/fastai
That's it. The only annoyance is you'll need an extra click. It will tell you:
We couldn’t find any repositories matching 'cnn_learner repo:fastai/fastai'
because by default it searches for repositories matching that search string...
So just click on the left on "Code" and it will display what you want.
Or get the code search results directly with a URL like this:
https://github.com/search?q=cnn_learner+repo%3Afastai%2Ffastai&type=code
Recent private repositories have a search field for searching through that repo.
Bafflingly, it looks like this functionality is not available to public repositories, though.
While @VonC's answer works for some repositories, unfortunately for many repositories you can't right now. Github is simply not indexing them (as commented originally by @emddudley). They haven't stated this anywhere on their website, but they will tell you if you ask support:
From: Tim Pease
We have stopped adding newly pushed code into our codesearch index. The volume of code has outgrown our current search index, and we are working on moving to a more scalable search architecture. I'm sorry for the annoyance. We do not have an estimate for when this new search index will be up and running, but when it is ready a blog post will be published (https://github.com/blog).
Annoyingly there is no way to tell which repositories are not indexed other than the lack of results (which also could be from a bad query).
There also is no way to track this issue other than waiting for them to blog it (or watching here on SO).
From: Tim Pease
I am afraid our issue tracker is internal, but we can notify you as soon as the new search index is up and running.
I search the source code inside of Github Repositories with the free Sourcegraph Chrome Extension ... But I Downloaded Chrome First, I knew other browsers support it though, such as - and maybe just only - Firefox.
I skimmed through SourceForge's Chrome Extension Docs and then also I looked at just what I needed for searching for directory names with Github's Search Engine itself, by reading some of Github's Codebase Searching Doc
Google allows you to search in the project, but not the code :(
UPDATE
The bookmarklet hack below is broken due to XHR issues and API changes.
Thankfully Github now has "A Whole New Code Search" which does the job superbly.
Checkout this voodoo: Github code search userscript.
Follow the directions there, or if you hate bloating your browser with scripts and extensions, use my bookmarkified bundle of the userscript:
javascript:(function(){var s='https://raw.githubusercontent.com/skratchdot/github-enhancement-suite/master/build/github-enhancement-suite.user.js',t='text/javascript',d=document,n=navigator,e;(e=d.createElement('script')).src=s;e.type=t;d.getElementsByTagName('head')[0].appendChild(e)})();doIt('');void('');
Save the source above as the URL of a new bookmark. Browse to any Github repo, click the bookmark, and bam: in-page, ajaxified code search.
CAVEAT Github must index a repo before you can search it.
Abracadabra...
Here's a sample search from the annotated ECMAScript 5.1 specification repository:
Source: Stackoverflow.com