When we are learning something new or trying to implement a new logic, we have all searched on the internet to find references. We might start off with the official documentation which in most cases is bulky or search on google to end up in Stack Overflow. But sometimes, even then you might not be able to get the solution that is specifically required. My go-to resort in such circumstances is GitHub's project repository. I will mention some of the advanced techniques you can use to nail down the search result to exactly what you are looking for.
You can do the following search techniques either inside a repository (eg: https://github.com/facebook/create-react-app) or in the global route of Github (eg: https://github.com/) based on where you want to look.
Filter based on language
React.useState language:typescript
We can search a term by specifying which programming language should the code be written in. In this case, GitHub will return the search results of everything written in "typescript"
Filter based on file extension
React.useRef extension:tsx
This command will return search results which have the file extension specified. In this example, we specified the file extension to look for as "tsx".
Use quotation marks when searching multi-word queries
"import Image from 'next/image'"
When searching a query with whitespace in between (having multiple words), always use quotation marks. Otherwise, GitHub will return results based on each word in the query instead of the whole query.
Always use quotation marks when searching for queries with multiple words
Filter based on label
package label:"bug fix"
This query will return all the GitHub issues that have the specified label attached to them. This is very useful when you are searching for "Issues" that were raised on a specific repo.
Filter based on user
user:SharooqSalaudeen extension:tsx
You can narrow your search result to all the repositories of a specific user with this command.
Filter based on the organisation
org:facebook extension:js
This is similar to the above-mentioned filtering based on "user". Search only the repositories of an organisation.
Filter based on a specific repository
repo:SharooqSalaudeen/amplify-twitter-clone extension:js
You can explicitly specify a repository on which you want to run the query on. This is similar to when you search when inside a repository page.
Filter based on a filename
pre_build filename:codebuild.yml
This will effectively search the query on the filename that is specified.
Filter out specific files based on a word
pre_build NOT post_build
This will effectively not show the results of files that contain the word "post_build" in them.
Filter based on the author's name
author:SharooqSalaudeen
This will only return the results that are connected with a specific author of the commits.
Filter issues that are assigned to me.
is:issue assignee:@me
This will show all the issues that are assigned to me. Here "@me" refers to the user that is logged in.
Conclusion
Hope this will improve your productivity in your journey to becoming a great programmer. If you are interested in similar posts, take a look at my home page to find similar articles.