Skip to content

Instantly share code, notes, and snippets.

@jpsilvashy
Created July 7, 2024 19:45
Show Gist options
  • Save jpsilvashy/76308aa9ac038973ddf40ff27720d06d to your computer and use it in GitHub Desktop.
Save jpsilvashy/76308aa9ac038973ddf40ff27720d06d to your computer and use it in GitHub Desktop.
Remove all the contents of your .gitignore file from the git history
#!/bin/bash
# Check if .gitignore file exists
if [ ! -f .gitignore ]; then
echo ".gitignore file not found!"
exit 1
fi
# Read each line in .gitignore
while IFS= read -r line
do
# Skip empty lines and comments
if [[ ! -z "$line" && ! "$line" =~ ^# ]]; then
# Remove leading slash if present
path="${line#/}"
echo "Removing path: $path"
git filter-repo --path "$path" --invert-paths
fi
done < .gitignore
# Force push the changes to the remote repository
git push --force --all
git push --force --tags
echo "Done removing paths listed in .gitignore"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment