Skip to content

Instantly share code, notes, and snippets.

@LordAmit
Last active January 23, 2026 03:02
Show Gist options
  • Select an option

  • Save LordAmit/cda97e185f3641af7830777404d31d8a to your computer and use it in GitHub Desktop.

Select an option

Save LordAmit/cda97e185f3641af7830777404d31d8a to your computer and use it in GitHub Desktop.
git-ignore
#!/bin/bash
# put it whereever path. then:
# git config --global alias.ignore '!/Users/<username>/<whereever>/git-ignore'
# Check if a filename was provided
if [ -z "$1" ]; then
echo "Usage: git ignore <filename>"
exit 1
fi
# Append the filename to .gitignore if it's not already there
if grep -Fxq "$1" .gitignore 2>/dev/null; then
echo "'$1' is already in .gitignore"
else
echo "$1" >> .gitignore
echo "Added '$1' to .gitignore"
fi
# Optional: Stop tracking the file if it's already in the index
git rm --cached "$1" 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment