Created
March 21, 2022 10:09
-
-
Save wookietreiber/8abde993fa4d42628c7b815826fcebeb to your computer and use it in GitHub Desktop.
ignore files with git
This file contains hidden or 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 | |
function usage { cat << EOF | |
usage: git ignore [--global|--local|--repo] PATTERN | |
ignores PATTERN in git | |
PATTERN may include wildcard. you may want to quote it: | |
# ignores all pdf files that are in the current directory | |
git ignore *.pdf | |
# ignores ALL pdf files | |
git ignore '*.pdf' | |
OPTIONS | |
--repo writes PATTERN to REPOSITORY/.gitignore (default) | |
--local writes PATTERN to REPOSITORY/.git/info/exclude | |
--global writes PATTERN to $HOME/.config/git/ignore | |
OTHER OPTIONS | |
-h, -? prints usage help | |
EOF | |
} | |
function ignore { | |
local pattern="$1" | |
local file="$2" | |
echo "$pattern" >> "$file" | |
} | |
case "$1" in | |
-h|-?) | |
usage | |
exit 0 | |
;; | |
--global) | |
ignore "$2" "$HOME/.config/git/ignore" | |
;; | |
--local) | |
ignore "$2" "$(git rev-parse --show-toplevel)/.git/info/exclude" | |
;; | |
--repo) | |
ignore "$2" "$(git rev-parse --show-toplevel)/.gitignore" | |
;; | |
"") | |
usage >&2 | |
exit 1 | |
;; | |
*) | |
ignore "$1" "$(git rev-parse --show-toplevel)/.gitignore" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment