Peter Alfvin
Peter Alfvin

Reputation: 29389

Is it possible to search for a particular filename on GitHub?

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.

Upvotes: 266

Views: 193624

Answers (13)

Kamiccolo
Kamiccolo

Reputation: 8497

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?

EDIT: as of 2024 GitHub do seem to provide a way to search for a filename, despite the folder structure of the repository. Please check the "advanced search" section. It do seem to boil down to something like the following: https://github.com/search?q=path%3A**%2Ftest.c&type=code&ref=advsearch

Or rather q=path:**/test.c as it's query argument.

Upvotes: 38

Penny Liu
Penny Liu

Reputation: 17408

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. Then, press the t key. The file finder is now focused.

enter image description here

enter image description here



  1. Next, enter the filename of the desired file to open it.

enter image description here


More shortcuts for source code browsing.

Upvotes: 21

Kyr
Kyr

Reputation: 5491

I had the same problem and I followed GH suggestion to add asterisks for a path search:

path:**/user.rb

Upvotes: -1

User15239563
User15239563

Reputation: 391

What works for me is:

path:<filename>

To search for pyproject.toml file you would use

path:pyproject.toml

Upvotes: 2

Laurent Lyaudet
Laurent Lyaudet

Reputation: 938

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

Upvotes: 16

Vajk Hermecz
Vajk Hermecz

Reputation: 5702

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.

Upvotes: 3

Nagev
Nagev

Reputation: 13207

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.

Upvotes: 24

ajain
ajain

Reputation: 510

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

Upvotes: 2

Shah Vipul
Shah Vipul

Reputation: 747

  1. In git Repo Click on "Go to file". It will show "repo/".
  2. Enter specific file name.

Upvotes: 0

kenorb
kenorb

Reputation: 166359

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).

Upvotes: 111

Orangenhain
Orangenhain

Reputation: 4090

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/

Upvotes: 246

MaxChinni
MaxChinni

Reputation: 1216

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 ------------------------------------+

Upvotes: 7

Andy Lester
Andy Lester

Reputation: 93636

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

Upvotes: 10

Related Questions