Skip to content

Instantly share code, notes, and snippets.

@RazerM
Last active June 6, 2025 13:52
Show Gist options
  • Select an option

  • Save RazerM/8e33f20213360eec6abbf2035e4ee180 to your computer and use it in GitHub Desktop.

Select an option

Save RazerM/8e33f20213360eec6abbf2035e4ee180 to your computer and use it in GitHub Desktop.
`git exclude` to add paths to .git/info/exclude
[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