From 6705af5cbb027e624480ad58702664319d37a5bd Mon Sep 17 00:00:00 2001 From: Sebastian Preisner Date: Tue, 25 Jul 2017 20:19:39 +0000 Subject: [PATCH] Gitignore --- functions/git.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 functions/git.sh diff --git a/functions/git.sh b/functions/git.sh new file mode 100644 index 0000000..69e14e1 --- /dev/null +++ b/functions/git.sh @@ -0,0 +1,24 @@ +# 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 +} \ No newline at end of file