Last active
June 6, 2025 13:52
-
-
Save RazerM/8e33f20213360eec6abbf2035e4ee180 to your computer and use it in GitHub Desktop.
`git exclude` to add paths to .git/info/exclude
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
| [alias] | |
| exclude = "!f() { \ | |
| for file in \"$@\"; do \ | |
| relative_path=\"$(realpath --relative-to=. \"${GIT_PREFIX:-.}/$file\")\"; \ | |
| if git ls-files --error-unmatch \"$relative_path\" > /dev/null 2>&1; then \ | |
| echo \"'$relative_path' is tracked by git\"; \ | |
| elif ! git check-ignore -q \"$relative_path\"; then \ | |
| echo \"/$relative_path\" >> \".git/info/exclude\"; \ | |
| echo \"Added '/$relative_path' to .git/info/exclude\"; \ | |
| else \ | |
| echo \"'$relative_path' is already ignored\"; \ | |
| fi; \ | |
| done; \ | |
| }; f" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment