233

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
  • 15,447
  • 5
  • 79
  • 98
Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106
  • 1
    IMO it is bad design that GitHub search doesn't default to including filenames in results. Atm, if you search a repo for the name of a file, and the name of the file doesn't appear in the body of a file (only as the name of the file), then the file won't be returned in the results. – stevec Apr 11 '23 at 14:48
  • Just use `path:**/user.rb` – Michael Mior Sep 01 '23 at 17:55

11 Answers11

217

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
  • 3,724
  • 1
  • 22
  • 16
  • 11
    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
  • 3
    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
  • 2
    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
  • The file name needs to match (without extension), absolute waste of time if you guess a filename. Penny's answer is the better one for that case. – Martin Braun Sep 13 '22 at 20:05
  • Unfortunately, [`filename:DEVELOPER.md`](https://github.com/search?q=filename%3ADEVELOPER.md) returns not only `DEVELOPER.md` but `api-documentation-and-developer-portals.md` and `ClientDeveloperDocumentation.md` files as well. And even [`filename:"DEVELOPER.md"`](https://github.com/search?q=filename%3A%22DEVELOPER.md%22) doesn't help much. _You can't use the following wildcard characters as part of your search query: . , : ; / \ ` ' " = * ! ? # $ & + ^ | ~ < > ( ) { } [ ] @. The search will simply ignore these symbols._ – Ilya Serbis Feb 22 '23 at 21:42
  • This now gives the message "Possible unrecognized qualifier, searching for this term literally" – Michael Mior Sep 01 '23 at 17:54
105

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
  • 155,785
  • 88
  • 678
  • 743
  • 5
    This is the correct answer. Notice there aren't any spaces in the query. – Erik Mar 09 '18 at 17:03
  • 5
    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
  • I tried "filename:" and was suggested by GitHub to use "path:**/your-file-name". Seemed to work with just "path:your-file-name". – Omar Shishani Jul 26 '23 at 17:09
35

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
  • 7,758
  • 3
  • 34
  • 47
  • 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
  • Is there a way to permalink to the file finder with the search box pre-populated? It'd be nice if https://github.com/jquery/jquery/find/main/xyzzy would pre-fill "xyzzy" in the textbox. – Jedi Jul 11 '23 at 22:01
24

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.

This is now documented on Github.

Nagev
  • 10,835
  • 4
  • 58
  • 69
22

I would like to clarify @ajain's answer regarding accessing files in a Github repository via the web UI. Here are the steps:

  1. Firstly, you need to be in the repository's directory view.

enter image description here


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

enter image description here


  1. Enter the filename of the desired file to open it.

enter image description here


More shortcuts for source code browsing.

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
10

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

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
  • 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
  • 2
    what if my GitHub is private or hosted in a company domain.. not gonna work – Stunner Jan 20 '21 at 10:10
  • tried this and it had no results wheras github advanced search by filename found 3 copies of the modded file i need – Hicsy Apr 17 '23 at 04:11
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,206
  • 14
  • 21
2

You can also use path:**/user.rb

Laurent Lyaudet
  • 630
  • 8
  • 16
1

Just press T in the repository's directory view and it will let you search for a file.

Martin Braun
  • 10,906
  • 9
  • 64
  • 105
ajain
  • 444
  • 4
  • 7
  • 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
1
  1. In git Repo Click on "Go to file". It will show "repo/".
  2. Enter specific file name.
S.B
  • 13,077
  • 10
  • 22
  • 49
Shah Vipul
  • 625
  • 7
  • 11
1

As of recently, you should simply use path:user.rb. This will find files with the name anywhere inside repositories.

Note: The older approaches like file:user.rb and in:path user.rb seem to not work anymore.

Vajk Hermecz
  • 5,413
  • 2
  • 34
  • 25