Here's a little extra magic so that you don't even need to be in the root of the repository to create such a temporary file (you'll have to change the readlink invocation if you're on MacOS):
git-ignore-local () {
root=$(git rev-parse --show-toplevel)
path=$(readlink -f "$1")
# ${path#${root}} should suffice if you don't have realpath
relpath=$(relpath -m --relative-to="$root" "$path")
echo "$relpath" >> "${root}.git/info/exclude"
}
Edit: You could also put the function contents as an executable on your PATH called `git-ignore-local` then it becomes something you can invoke as `git ignore-local`.