Skip to content

Instantly share code, notes, and snippets.

@jeremysimmons
Created May 9, 2025 22:36
Show Gist options
  • Select an option

  • Save jeremysimmons/78cb74b475ec4a77ff4e8701d4ed5d56 to your computer and use it in GitHub Desktop.

Select an option

Save jeremysimmons/78cb74b475ec4a77ff4e8701d4ed5d56 to your computer and use it in GitHub Desktop.
I don't want to see me coworkers work.
# .git/config - local repo config
# limit to only files you want to see. your branches begin with your git username by convention
[remote "origin"]
fetch = +refs/heads/main:refs/remotes/origin/main
fetch = +refs/heads/jeremysimmons/*:refs/remotes/origin/jeremysimmons/*
#!/bin/bash
# Exit on error
set -e
# Fetch latest from origin
git fetch --prune
echo "Cleaning up remote-tracking branches except 'origin/main' and 'origin/jeremysimmons/*'..."
# List all remote-tracking branches
git branch -r | while read -r remote; do
# Skip origin/main and origin/jeremysimmons/*
if [[ "$remote" == "origin/main" || "$remote" == origin/jeremysimmons/* ]]; then
continue
fi
# Remove the remote-tracking branch locally
# Strip "origin/" prefix to get the actual ref name
ref="${remote#origin/}"
echo "Deleting remote-tracking branch: $remote"
git branch -dr "origin/$ref" || true
done
echo "Cleanup complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment