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