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.
Does the search user.rb in:path
do what you want to do?
Alternatively there is also this search filename:user.rb
-
3using
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 -
1This 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 6 '16 at 16:15
-
2Yes, 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 6 '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
-
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).
-
2
-
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 1 at 19:25
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?
-
1Yeah, 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
-
4oh, so You've tried
some_weird_file_Youre_looking_for.ext in:path
too? Because it does work 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 haduser.rb
at the top level. – Peter Alfvin Sep 24 '13 at 21:14 -
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 8:35
-
1Note 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. Combine this with a custom chrome search engine and you can search your target repo super fast for a filename – Brad Parks Mar 26 at 12:13
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.
You can try Google. Google for filename.txt site:github.com
.
-
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 at 10:10
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 ------------------------------------+
I would like to clarify @ajain's answer.
- In Github Web UI, you have to already be in the Reop's directory view.
- Then, press the T key. A file finder appears.
- Enter a filename to open it.
More shortcuts for source code browsing.
-
1
Just press "t" and It will let you search for a file.
-
1Bit of clarification: you have to already be in the Reop's directory view. See @Kamiccolo's answer below – tfantina Nov 5 '19 at 19:14
ls
instead of find – meda Sep 24 '13 at 21:01