Skip to content

Instantly share code, notes, and snippets.

@juliovedovatto
Created June 3, 2021 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliovedovatto/ea51679a85ed6c68ef90ee2cb0bef893 to your computer and use it in GitHub Desktop.
Save juliovedovatto/ea51679a85ed6c68ef90ee2cb0bef893 to your computer and use it in GitHub Desktop.
GIT: ignoring files locally only (bash script)
#!/bin/bash
set -e
GIT_EXCLUDE_FILE="./.git/info/exclude"
[ "$#" -lt 1 ] && echo -e "Please give at least one argument" && exit 1
[ ! -d "./.git" ] && echo -e "It seems this directory is not a root dir of a git repo. Aborting." && exit 1
for file in "$@"
do
SKIP_FILE=false
if [ ! -e "${file}" ]; then
while true; do
read -p "It seems this file/directory does not exists. Add it anyway? [Y/n]" answer
case "${answer}" in
[Nn]* ) SKIP_FILE=true; break;;
[Yy]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
[ "${SKIP_FILE}" = true ] && continue
echo "${file}" >> "${GIT_EXCLUDE_FILE}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment