blob: 03056dad0de5ab6121c1f7a506dc4dacf1f83c7c [file] [log] [blame]
Pavel Roskinc3b831b2006-04-05 02:00:48 -04001git-clean(1)
2============
3
4NAME
5----
6git-clean - Remove untracked files from the working tree
7
8SYNOPSIS
9--------
10[verse]
Jiang Xin17696002013-06-25 23:53:48 +080011'git clean' [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>...
Pavel Roskinc3b831b2006-04-05 02:00:48 -040012
13DESCRIPTION
14-----------
Wesley J. Landaker911198f2009-04-25 09:13:41 -060015
Junio C Hamano6a260f52009-05-06 10:48:26 -070016Cleans the working tree by recursively removing files that are not
17under version control, starting from the current directory.
Wesley J. Landaker911198f2009-04-25 09:13:41 -060018
Matthieu Moy23f82392016-06-28 13:40:10 +020019Normally, only files unknown to Git are removed, but if the `-x`
Wesley J. Landaker911198f2009-04-25 09:13:41 -060020option is specified, ignored files are also removed. This can, for
21example, be useful to remove all build products.
22
Abhijit Menon-Senf448e242008-07-30 15:03:43 +053023If any optional `<path>...` arguments are given, only those paths
24are affected.
Junio C Hamano393e3b12006-05-08 12:02:44 -070025
Pavel Roskinc3b831b2006-04-05 02:00:48 -040026OPTIONS
27-------
28-d::
29 Remove untracked directories in addition to untracked files.
Thomas Ackermann2de9b712013-01-21 20:17:53 +010030 If an untracked directory is managed by a different Git
Junio C Hamanoa0f4afb2009-06-30 15:33:45 -070031 repository, it is not removed by default. Use -f option twice
32 if you really want to remove such a directory.
Pavel Roskinc3b831b2006-04-05 02:00:48 -040033
Josh Triplett21225912007-04-23 17:18:16 -070034-f::
René Scharfef7aec122009-08-29 11:05:00 +020035--force::
Thomas Ackermann2de9b712013-01-21 20:17:53 +010036 If the Git configuration variable clean.requireForce is not set
Mikko Rapelibcd57cb2015-02-26 15:16:49 +020037 to false, 'git clean' will refuse to delete files or directories
38 unless given -f, -n or -i. Git will refuse to delete directories
39 with .git sub directory or file unless a second -f
Matt McCutchen31e3c2d2016-02-06 15:25:41 -050040 is given.
Jiang Xin17696002013-06-25 23:53:48 +080041
42-i::
43--interactive::
Jiang Xinc0be6b42013-06-25 23:53:55 +080044 Show what would be done and clean files interactively. See
45 ``Interactive mode'' for details.
Josh Triplett21225912007-04-23 17:18:16 -070046
Pavel Roskinc3b831b2006-04-05 02:00:48 -040047-n::
Stephan Beyer459cf2e2008-06-08 03:36:10 +020048--dry-run::
Pavel Roskinc3b831b2006-04-05 02:00:48 -040049 Don't actually remove anything, just show what would be done.
50
51-q::
Stephan Beyer459cf2e2008-06-08 03:36:10 +020052--quiet::
Pavel Roskinc3b831b2006-04-05 02:00:48 -040053 Be quiet, only report errors, but not the files that are
54 successfully removed.
55
Jared Hance07de4eb2010-07-20 15:35:56 -040056-e <pattern>::
57--exclude=<pattern>::
Junio C Hamanob6194672011-08-25 11:29:57 -070058 In addition to those found in .gitignore (per directory) and
59 $GIT_DIR/info/exclude, also consider these patterns to be in the
60 set of the ignore rules in effect.
Jared Hance07de4eb2010-07-20 15:35:56 -040061
Pavel Roskinc3b831b2006-04-05 02:00:48 -040062-x::
Junio C Hamanob6194672011-08-25 11:29:57 -070063 Don't use the standard ignore rules read from .gitignore (per
64 directory) and $GIT_DIR/info/exclude, but do still use the ignore
65 rules given with `-e` options. This allows removing all untracked
Pavel Roskinc3b831b2006-04-05 02:00:48 -040066 files, including build products. This can be used (possibly in
Thomas Rast0b444cd2010-01-10 00:33:00 +010067 conjunction with 'git reset') to create a pristine
Pavel Roskinc3b831b2006-04-05 02:00:48 -040068 working directory to test a clean build.
69
70-X::
Thomas Ackermann2de9b712013-01-21 20:17:53 +010071 Remove only files ignored by Git. This may be useful to rebuild
Pavel Roskinc3b831b2006-04-05 02:00:48 -040072 everything from scratch, but keep manually created files.
73
Jiang Xinc0be6b42013-06-25 23:53:55 +080074Interactive mode
75----------------
76When the command enters the interactive mode, it shows the
77files and directories to be cleaned, and goes into its
78interactive command loop.
79
80The command loop shows the list of subcommands available, and
81gives a prompt "What now> ". In general, when the prompt ends
82with a single '>', you can pick only one of the choices given
83and type return, like this:
84
85------------
86 *** Commands ***
87 1: clean 2: filter by pattern 3: select by numbers
88 4: ask each 5: quit 6: help
89 What now> 1
90------------
91
92You also could say `c` or `clean` above as long as the choice is unique.
93
94The main command loop has 6 subcommands.
95
96clean::
97
98 Start cleaning files and directories, and then quit.
99
100filter by pattern::
101
102 This shows the files and directories to be deleted and issues an
Thomas Ackermannf745acb2014-11-03 21:37:07 +0100103 "Input ignore patterns>>" prompt. You can input space-separated
Jiang Xinc0be6b42013-06-25 23:53:55 +0800104 patterns to exclude files and directories from deletion.
105 E.g. "*.c *.h" will excludes files end with ".c" and ".h" from
106 deletion. When you are satisfied with the filtered result, press
107 ENTER (empty) back to the main menu.
108
109select by numbers::
110
111 This shows the files and directories to be deleted and issues an
112 "Select items to delete>>" prompt. When the prompt ends with double
113 '>>' like this, you can make more than one selection, concatenated
114 with whitespace or comma. Also you can say ranges. E.g. "2-5 7,9"
115 to choose 2,3,4,5,7,9 from the list. If the second number in a
Jiang Xin309422e2013-07-24 06:22:43 +0800116 range is omitted, all remaining items are selected. E.g. "7-" to
Jiang Xinc0be6b42013-06-25 23:53:55 +0800117 choose 7,8,9 from the list. You can say '*' to choose everything.
118 Also when you are satisfied with the filtered result, press ENTER
119 (empty) back to the main menu.
120
121ask each::
122
123 This will start to clean, and you must confirm one by one in order
124 to delete items. Please note that this action is not as efficient
125 as the above two actions.
126
127quit::
128
129 This lets you quit without do cleaning.
130
131help::
132
133 Show brief usage of interactive git-clean.
134
Philip Oakley068c6742012-09-19 00:25:33 +0100135SEE ALSO
136--------
137linkgit:gitignore[5]
138
Pavel Roskinc3b831b2006-04-05 02:00:48 -0400139GIT
140---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200141Part of the linkgit:git[1] suite