160

I know that the GitHub web interface lets you search all repositories for files with a particular pathname (e.g. searching for path:/app/models/user.rb yields > 109k results), but is there a way to search all repositories for filenames independent of their subdirectory location? I tried using asterisks in the path argument, and that didn't seem to work.

Penny Liu
  • 7,720
  • 5
  • 40
  • 66
Peter Alfvin
  • 26,897
  • 7
  • 60
  • 98
  • what is the command you run? have you try with `ls` instead of find – meda Sep 24 '13 at 21:01
  • 1
    I was referring to the web interface - that's all I've tried. – Peter Alfvin Sep 24 '13 at 21:19
  • 8
    To whoever downvoted, I'm quite clueless as to the reason. I know this is not a "programming question", but it seems like a "programming tools" question and there are other github questions on the site. If it's about question quality, I'd appreciate more information or a vote-to-close so that I can see what you're referring to. – Peter Alfvin Sep 24 '13 at 23:04

8 Answers8

142

Does the search user.rb in:path do what you want to do? Alternatively there is also this search filename:user.rb

Found on: https://help.github.com/articles/searching-code/

Orangenhain
  • 2,816
  • 1
  • 18
  • 14
  • 3
    using `in:path YOUR_FILENAME_HERE` works great - and super importantly, works cross repo so you can search your entire organizations repos to find which repos contain a certain filename. Nice! – Brad Parks Apr 22 '16 at 16:45
  • 1
    This is no longer possible. The searches you link return the following error: "We could not perform this search. Must include at least one user, organization, or repository" – Jaap Joris Vens Sep 06 '16 at 16:15
  • 2
    Yes, they do ... you just have to be logged into GitHub for it to work. Don't know when they changed that. It's a general issue for code search, not just those specific searches. – Orangenhain Sep 06 '16 at 20:37
  • It's a pity it only does "path contains this string anywhere" and not like filename globs or anything like that :| – rogerdpack May 17 '19 at 23:09
  • How to search by extension only? – AnupamChugh Aug 28 '20 at 12:35
  • 1
    My god I wasted a lot of time not realizing that free text search doedsn't include filenames but content only. – Sridhar Sarnobat Apr 15 '21 at 21:16
68

In search input, you can use filename parameter to search in multiple repositories, for example:

filename:my_filename.txt

If you're looking for a filename in specific repository, you can just press t and start typing the file name (see: GH keyboard shortcuts).

kenorb
  • 118,428
  • 63
  • 588
  • 624
  • 2
    This is the correct answer. Notice there aren't any spaces in the query. – Erik Mar 09 '18 at 17:03
  • 1
    it is very funny how searching for **myfile.txt** gives nothing and adding those magic `filename:` prefix makes the search return one file... GitHub, why?! :) – RAM237 Feb 01 '21 at 19:25
30

GitHub introduced FileFinder in 2011.

Try it out: just hit t on any repo's file or directory view.[1]

So, You're still restricted to repository.

[1]https://github.com/blog/793-introducing-the-file-finder

Another approach to Your question:

Can I use Git to search for matching filenames in a repository?

Community
  • 1
  • 1
Kamiccolo
  • 5,791
  • 3
  • 35
  • 42
  • 1
    Yeah, I knew about that and should have mentioned it in my question. So there's no way to search across repositories? If not, do you know if there is any technical reason why not? – Peter Alfvin Sep 24 '13 at 21:05
  • 4
    oh, so You've tried `some_weird_file_Youre_looking_for.ext in:path` too? Because it [does work](https://github.com/search?q=index.php+in%3Apath&ref=cmdform) for me... – Kamiccolo Sep 24 '13 at 21:11
  • nope, but I just tried `path:user.rb` and it only gave me 324 results, all which had `user.rb` at the top level. – Peter Alfvin Sep 24 '13 at 21:14
  • And it looks like your results for `index.php` are all at the top level as well. – Peter Alfvin Sep 24 '13 at 21:16
  • @PeterAlfvin yup, it appears to be just on top either... *sigh* – Kamiccolo Sep 24 '13 at 21:19
  • 1
    @Kamiccolo you should post this as an answer, because that's exactly the right answer! Peter Alfvin should accept it as well... the important bit is in:path. Verified that it works no matter where the filename is in the path as well, not just for top-level files. – Sam Salisbury May 15 '15 at 08:35
  • 1
    Note that once you've entered that mode, the url changes. You can bookmark that changed url, and when you go back to it, you're automatically entered into the "find" mode for searching for a file in a repo/branch. e.g. [for jquery](https://github.com/jquery/jquery/find/main). Combine this with a [custom chrome search engine](https://zapier.com/blog/add-search-engine-to-chrome/) and you can search your target repo super fast for a filename – Brad Parks Mar 26 '21 at 12:13
11

In my case, I wanted to search for a particular file name, in all of my organization's repositories. This can be done by entering this in the search box:

org:your-organization-user-name filename:the-file-name

Of course, just do "filename:the-file-name" if you want to search the whole of GitHub.

I didn't see this in https://help.github.com/articles/searching-code/ but found out when I switched context, and GitHub entered the filter for me automaticallly.

Nagev
  • 4,017
  • 1
  • 29
  • 35
9

You can try Google. Google for filename.txt site:github.com.

Andy Lester
  • 81,480
  • 12
  • 93
  • 144
  • 1
    +1 for what I assume matches not only current filenames, but any files which include that text as well as some number of filenames from earlier versions of the repositories. – Peter Alfvin Sep 24 '13 at 21:33
  • what if my GitHub is private or hosted in a company domain.. not gonna work – Stunner Jan 20 '21 at 10:10
7

I refined @andy-lester answer with intitle:, i.e. I want to find where's located the file simple_spinner_item.xml in Android's source code hosted on github, so I search on Google this string:

site:github.com intitle:simple_spinner_item.xml github.com/android

^                       ^                       ^
|                       |                       |
on github site          |                       |
                        |                       |
filename I'm searching -+                       |
                                                |
github user ------------------------------------+
Community
  • 1
  • 1
MaxChinni
  • 1,032
  • 11
  • 20
3

I would like to clarify @ajain's answer.

  1. In Github Web UI, you have to already be in the Reop's directory view.

enter image description here


  1. Then, press the T key. A file finder appears.

enter image description here


  1. Enter a filename to open it.

enter image description here


More shortcuts for source code browsing.

Penny Liu
  • 7,720
  • 5
  • 40
  • 66
-4

Just press "t" and It will let you search for a file.

ajain
  • 212
  • 2
  • 6
  • 1
    Bit of clarification: you have to already be in the Reop's directory view. See @Kamiccolo's answer below – tfantina Nov 05 '19 at 19:14