# Remove file from git versioning and add to .gitignore ######################################################### gitignore() { # Current Folder a Git Repository? if ! git rev-parse --is-inside-work-tree &> /dev/null ; then echo "Current folder is no Git Repository" return 1 fi gitworktree=`git rev-parse --show-toplevel` # found on https://stackoverflow.com/questions/12293944/how-to-find-the-path-of-the-local-git-repository-when-i-am-possibly-in-a-subdire # Create .gitignore if not exist if [ ! -e "${gitworktree}/.gitignore" ]; then echo "Creat new ${gitworktree}/.gitignore file" touch ${gitworktree}/.gitignore fi for file in "$@"; do # Remove file from history echo "removing $file from git history" git rm --cached -r "$file" echo $file >> .gitignore done }