-
-
Save brock/46ec839c859b1c4c1d35add1bfe27eff to your computer and use it in GitHub Desktop.
GRU: Git Remove Untracked Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# gru | |
# Git Remove Untracked (files) | |
# without this script, you have to manually delete files and directories in your git directory if | |
# you want to delete them and they are not tracked by git. | |
# this works as an alias or an executable file | |
# Explanation: | |
# git status -s (display the git status of each file, one line at a time, in short format) | |
# grep '^??' (untracked files will begin with ??) | |
# cut -d\ -f2- (get the path to the file, explained here: http://stackoverflow.com/a/9004039/2083544) | |
# xargs -I \{\} rm -rf "{}" (pipe the filepath or directory to the remove command) | |
git status -s | grep '^??' | cut -d\ -f2- | xargs -I \{\} rm -rf "{}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment