GIT-CLEAN(1)

✨ git-clean(1) β€” the girlies' guide to yeeting untracked files πŸ’…

okay so bestie, welcome to git-clean(1), your new favorite manual page πŸŽ€ she lives in the git manual family, and she is literally about to help you clean up your working tree. no cap.


🌸 NAME 🌸

git-clean β€” remove untracked files from the working tree 🧹✨


πŸ¦‹ SYNOPSIS πŸ¦‹

git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] [<pathspec>...]

that's the whole vibe check right there, bestie πŸ’–


πŸ‘‘ DESCRIPTION πŸ‘‘

okay so what does she actually do? she cleans your working tree by recursively removing files that are not under version control, starting from the current directory 🫢 think of her as that friend who comes over and just... starts throwing things away. iconic. terrifying. effective.

normally, only files unknown to Git get removed β€” that's the default, that's the lane she stays in. but if you specify the -x option, ignored files are also removed 😭 which is, for example, super useful to remove all build products. yes queen, wipe the whole build folder.

and if you give her any optional <pathspec>... arguments, only those paths that match the pathspec are affected 🎯 she's not gonna touch anything outside your little target zone.


✨ OPTIONS ✨

  • -d β€” okay so normally, when no <pathspec> is specified, git clean will not recurse into untracked directories, because she's trying not to remove too much πŸ™ˆ specify -d to have her recurse into those directories as well. but listen: if a <pathspec> is specified, -d is irrelevant β€” all untracked files matching the specified paths (with exceptions for nested git directories mentioned under --force) will be removed. so like, it stops mattering. iykyk.
  • -f, --force β€” the safety latch πŸ”’ if the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f. and it gets spicier: Git will refuse to modify untracked nested git repositories (directories with a .git subdirectory) unless a second -f is given 😳 yes, two. double force. double the commitment.
  • -i, --interactive β€” show what would be done and clean files interactively πŸ’… see "Interactive mode" for details. and good news: the configuration variable clean.requireForce is ignored here, because this mode gives its own safety protection by going interactive. she's got her own seatbelt, bestie πŸŽ€
  • -n, --dry-run β€” don't actually remove anything, just show what would be done πŸ‘€ literally a look-only mode, no touching. the configuration variable clean.requireForce is ignored here too, since nothing will be deleted anyway. so you can be nosy for free πŸ“
  • -q, --quiet β€” be quiet 🀫 only report errors, but not the files that are successfully removed. she still tells you when things go wrong tho, because communication is key.
  • -e <pattern>, --exclude=<pattern> β€” use the given exclude pattern in addition to the standard ignore rules (see gitignore(5)) 🧚 so you're stacking your own rules on top of the usual ones.
  • -x β€” don't use the standard ignore rules (see gitignore(5)), but still use the ignore rules given with -e options from the command line πŸ”₯ this allows removing all untracked files, including build products. this can be used (possibly in conjunction with git restore or git reset) to create a pristine working directory to test a clean build ✨ pristine. immaculate. that's the energy.
  • -X β€” remove only files ignored by Git 🌈 this may be useful to rebuild everything from scratch, but keep manually created files. so your handcrafted little guys stay safe 🫢

πŸ’€ INTERACTIVE MODE πŸ’€

when the command enters the interactive mode, it shows the files and directories to be cleaned, and goes into its interactive command loop πŸ”

the command loop shows the list of subcommands available, and gives a prompt What now> . in general, when the prompt ends with a single >, you can pick only one of the choices given and type return, like this:

*** Commands ***
    1: clean                2: filter by pattern    3: select by numbers
    4: ask each             5: quit                 6: help
What now> 1

you also could say c or clean above as long as the choice is unique πŸ‘‘ abbreviations slay, ambiguity does not.

the main command loop has 6 subcommands β€” here they are, one by one:

✨ the subcommands ✨

  • clean β€” start cleaning files and directories, and then quit πŸ§ΉπŸ’¨ that's it. that's the whole thing. go off.
  • filter by pattern β€” this shows the files and directories to be deleted and issues an Input ignore patterns>> prompt πŸ” you can input space-separated patterns to exclude files and directories from deletion. e.g. *.c *.h will exclude files ending with .c and .h from deletion. when you are satisfied with the filtered result, press ENTER (empty) to go back to the main menu πŸŽ€
  • select by numbers β€” this shows the files and directories to be deleted and issues a Select items to delete>> prompt πŸ”’ when the prompt ends with double >> like this, you can make more than one selection, concatenated with whitespace or comma. also you can say ranges πŸ‘ e.g. 2-5 7,9 to choose 2,3,4,5,7,9 from the list. if the second number in a range is omitted, all remaining items are selected β€” e.g. 7- to choose 7,8,9 from the list. you can say * to choose everything. also when you are satisfied with the filtered result, press ENTER (empty) back to the main menu πŸ’–
  • ask each β€” this will start to clean, and you must confirm one by one in order to delete items 😭 please note that this action is not as efficient as the above two actions. it's giving careful and slow, but honest work.
  • quit β€” this lets you quit without doing any cleaning πŸ™ˆ no damage, no cleanup, we simply leave.
  • help β€” show brief usage of interactive git-clean 🫢 the built-in tutorial bestie.

πŸŽ€ CONFIGURATION πŸŽ€

okay so heads up: everything below this line in this section is selectively included from the git-config(1) documentation. the content is the same as what's found there πŸ“– so it's a little guest appearance from another manpage.

  • clean.requireForce β€” a boolean to make git-clean refuse to delete files unless -f is given. defaults to true ⭐ so yeah, by default she's asking for the force flag. that's the whole personality of this config variable, and honestly? fair.

πŸ¦‹ SEE ALSO πŸ¦‹

gitignore(5) β€” go read it, it's the ignore-rules lore you need 🌸


🌈 GIT 🌈

part of the git(1) suite πŸ‘‘ one big happy family of tools.


and that's the page, bestie πŸ’œ go forth, run git clean -n first like a responsible icon, and remember: with great -f comes great responsibility 😭✨

this page brought to you by Git 2.56.0, dated 2026-09-27 β€” mwah, stan the git suite πŸŽ€πŸ’…

πŸ“¦ where this page comes from