1GH-SEARCH-CODE(1) GitHub CLI manual GH-SEARCH-CODE(1)
2
3
4
6 gh-search-code - Search within code
7
8
9
11 gh search code <query> [flags]
12
13
14
16 Search within code in GitHub repositories.
17
18
19 The search syntax is documented at: https://docs.github.com/search-
20 github/searching-on-github/searching-code
21 ⟨https://docs.github.com/search-github/searching-on-github/searching-
22 code⟩
23
24
25 Note that these search results are powered by what is now a legacy
26 GitHub code search engine. The results might not match what is seen on
27 GitHub.com, and new features like regex search are not yet available
28 via the GitHub API.
29
30
31
33 --extension <string>
34 Filter on file extension
35
36
37 --filename <string>
38 Filter on filename
39
40
41 -q, --jq <expression>
42 Filter JSON output using a jq expression
43
44
45 --json <fields>
46 Output JSON with the specified fields
47
48
49 --language <string>
50 Filter results by language
51
52
53 -L, --limit <int>
54 Maximum number of code results to fetch
55
56
57 --match <strings>
58 Restrict search to file contents or file path: {file|path}
59
60
61 --owner <strings>
62 Filter on owner
63
64
65 -R, --repo <strings>
66 Filter on repository
67
68
69 --size <string>
70 Filter on size range, in kilobytes
71
72
73 -t, --template <string>
74 Format JSON output using a Go template; see "gh help formatting"
75
76
77 -w, --web
78 Open the search query in the web browser
79
80
81
83 # search code matching "react" and "lifecycle"
84 $ gh search code react lifecycle
85
86 # search code matching "error handling"
87 $ gh search code "error handling"
88
89 # search code matching "deque" in Python files
90 $ gh search code deque --language=python
91
92 # search code matching "cli" in repositories owned by microsoft organization
93 $ gh search code cli --owner=microsoft
94
95 # search code matching "panic" in the GitHub CLI repository
96 $ gh search code panic --repo cli/cli
97
98 # search code matching keyword "lint" in package.json files
99 $ gh search code lint --filename package.json
100
101
102
103
104
106 gh-search(1)
107
108
109
110 Oct 2023 GH-SEARCH-CODE(1)