1GIT-CLEAN(1) Git Manual GIT-CLEAN(1)
2
3
4
6 git-clean - Remove untracked files from the working tree
7
9 git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] [<pathspec>...]
10
12 Cleans the working tree by recursively removing files that are not
13 under version control, starting from the current directory.
14
15 Normally, only files unknown to Git are removed, but if the -x option
16 is specified, ignored files are also removed. This can, for example, be
17 useful to remove all build products.
18
19 If any optional <pathspec>... arguments are given, only those paths
20 that match the pathspec are affected.
21
23 -d
24 Normally, when no <pathspec> is specified, git clean will not
25 recurse into untracked directories to avoid removing too much.
26 Specify -d to have it recurse into such directories as well. If a
27 <pathspec> is specified, -d is irrelevant; all untracked files
28 matching the specified paths (with exceptions for nested git
29 directories mentioned under --force) will be removed.
30
31 -f, --force
32 If the Git configuration variable clean.requireForce is not set to
33 false, git clean will refuse to delete files or directories unless
34 given -f or -i. Git will refuse to modify untracked nested git
35 repositories (directories with a .git subdirectory) unless a second
36 -f is given.
37
38 -i, --interactive
39 Show what would be done and clean files interactively. See
40 “Interactive mode” for details.
41
42 -n, --dry-run
43 Don’t actually remove anything, just show what would be done.
44
45 -q, --quiet
46 Be quiet, only report errors, but not the files that are
47 successfully removed.
48
49 -e <pattern>, --exclude=<pattern>
50 Use the given exclude pattern in addition to the standard ignore
51 rules (see gitignore(5)).
52
53 -x
54 Don’t use the standard ignore rules (see gitignore(5)), but still
55 use the ignore rules given with -e options from the command line.
56 This allows removing all untracked files, including build products.
57 This can be used (possibly in conjunction with git restore or git
58 reset) to create a pristine working directory to test a clean
59 build.
60
61 -X
62 Remove only files ignored by Git. This may be useful to rebuild
63 everything from scratch, but keep manually created files.
64
66 When the command enters the interactive mode, it shows the files and
67 directories to be cleaned, and goes into its interactive command loop.
68
69 The command loop shows the list of subcommands available, and gives a
70 prompt "What now> ". In general, when the prompt ends with a single >,
71 you can pick only one of the choices given and type return, like this:
72
73 *** Commands ***
74 1: clean 2: filter by pattern 3: select by numbers
75 4: ask each 5: quit 6: help
76 What now> 1
77
78 You also could say c or clean above as long as the choice is unique.
79
80 The main command loop has 6 subcommands.
81
82 clean
83 Start cleaning files and directories, and then quit.
84
85 filter by pattern
86 This shows the files and directories to be deleted and issues an
87 "Input ignore patterns>>" prompt. You can input space-separated
88 patterns to exclude files and directories from deletion. E.g. "*.c
89 *.h" will exclude files ending with ".c" and ".h" from deletion.
90 When you are satisfied with the filtered result, press ENTER
91 (empty) back to the main menu.
92
93 select by numbers
94 This shows the files and directories to be deleted and issues an
95 "Select items to delete>>" prompt. When the prompt ends with double
96 >> like this, you can make more than one selection, concatenated
97 with whitespace or comma. Also you can say ranges. E.g. "2-5 7,9"
98 to choose 2,3,4,5,7,9 from the list. If the second number in a
99 range is omitted, all remaining items are selected. E.g. "7-" to
100 choose 7,8,9 from the list. You can say * to choose everything.
101 Also when you are satisfied with the filtered result, press ENTER
102 (empty) back to the main menu.
103
104 ask each
105 This will start to clean, and you must confirm one by one in order
106 to delete items. Please note that this action is not as efficient
107 as the above two actions.
108
109 quit
110 This lets you quit without doing any cleaning.
111
112 help
113 Show brief usage of interactive git-clean.
114
116 Everything below this line in this section is selectively included from
117 the git-config(1) documentation. The content is the same as what’s
118 found there:
119
120 clean.requireForce
121 A boolean to make git-clean do nothing unless given -f, -i, or -n.
122 Defaults to true.
123
125 gitignore(5)
126
128 Part of the git(1) suite
129
130
131
132Git 2.43.0 11/20/2023 GIT-CLEAN(1)