GitHub Find file by its content
Asked Answered
T

1

19

Can I filter files in a GitHub repository by file content?

For example, there is the public repo:

https://github.com/xamarin/mobile-samples.

I know that I can find file by name using this option:

https://github.com/xamarin/mobile-samples/find/master

But, can I filter results to files containing specified text eg. "Entry"?

Is there some query-string which I can use to do that?

I mean something like this: https://github.com/xamarin/mobile-samples?content=entry

Tequila answered 15/12, 2018 at 15:51 Comment(0)
T
29

UPDATE:

GitHub now provides whole new UI when search is opened.

You can search whole GitHub, organization of repository you are viewing currently or only repository.

Just typing "Entry" would open UI in which you can see mentions in Code, Issues, PRs, Discussions etc. You can filter by file extension, path etc. just by clicking on it.

GitHub Search

OLD ANSWER:

Just open repository, go to top search bar (where you search for other repos) and type:

Entry

Select to search in current repository, not "All GitHub".

To search for term in particular file of repository type:

Entry filename:example_filename.java

It will display all "Entry" in particular file.

Tanta answered 15/12, 2018 at 18:5 Comment(5)
Just to add a little something: the syntax seems to be <search term> filename:<filename> and you may search for it in your organization only (by adding org:<your organization name>. Works well with GitHub Enterprise.Airs
for info: Fork repo can not be searchShay
This answer might be outdated; to verify I have literally copy/pasted part of a comment in a file, and it couldn't find any results at all.Adonai
@Adonai Yeah, I agree. The UI was different when I answered it few years ago. I have updated the answer. Current UI is intuitiveTanta
I wouldn't say intuitive - I was literally unable to use it to get to what I was looking for myself (it claimed a total lack of results), but apparently it doesn't search the content of files above a certain size? If I knew more, I'd write an answer myself.Adonai

© 2022 - 2024 — McMap. All rights reserved.