Removing a Contributor from a GitHub Repository
This guide outlines the complete process for removing a contributor from a GitHub repository, including rewriting Git history to remove their commits and forcing cache updates on GitHub to reflect the changes.
Removing a contributor from a repository involves several steps:
- History Rewriting - Remove contributor commits using
git filter-repo - Force Push - Update the remote repository with cleaned history
- Cache Invalidation - Force GitHub to refresh contributor data
- Support Contact - Final escalation if automated methods fail
- Administrative access to the target repository
- git-filter-repo installed (available via Nix:
nix-shell -p git-filter-repo) - GitHub CLI (gh) for repository management
- Backup of the repository before making destructive changes
The first step is to remove the contributor’s commits from the Git history using git filter-repo, a powerful and safe tool for rewriting repository history.
git filter-repo --invert-paths --path-to-remove path/to/contributors/code
To remove specific commit message content (such as Co-Authored-By trailers):
nix-shell -p git-filter-repo --run "git filter-repo --message-callback 'return re.sub(b"\\n\\nCo-Authored-By: Claude <noreply@anthropic.com>\\n", b"", message)' --force"
This command uses git filter-repo to rewrite commit messages and remove the specified Co-Authored-By trailer.
Once the history has been rewritten, force push the changes to overwrite the existing history on the remote repository.
git push --force
Even after rewriting history and force-pushing changes, the old contributor may still appear on GitHub due to caching. Use the branch rename strategy to force a cache update:
Renaming the default branch can trigger cache invalidation on GitHub:
-
Rename the local branch:
git branch -m main main-temp -
Push the renamed branch:
git push origin main-temp -
Update GitHub’s default branch:
gh repo edit <owner>/<repo> --default-branch main-temp -
Remove the old branch:
git push origin --delete main -
Rename back to original:
git branch -m main-temp main -
Push the restored branch:
git push origin main -
Restore default branch setting:
gh repo edit <owner>/<repo> --default-branch main -
Clean up temporary branch:
git push origin --delete main-temp
git-filter-repo not found:
# Install via Nix
nix-shell -p git-filter-repo
# Or install globally
nix-env -iA nixpkgs.git-filter-repo
Force push rejected:
- Verify you have admin access to the repository
- Check if branch protection rules prevent force pushes
- Temporarily disable branch protection if needed
GitHub CLI authentication:
# Login to GitHub CLI
gh auth login
# Verify authentication
gh auth status
- Backup First - Always create a backup before rewriting history
- Coordinate with Team - Notify team members of history rewriting
- Update Local Clones - Team members will need to re-clone or reset their local repositories
- Review Changes - Verify the contributor has been completely removed
- git-filter-repo Documentation: GitHub Repository
- GitHub CLI: Official Documentation
- Git Documentation: Git SCM