GitRebrand
A Node.js CLI tool that automatically updates your old GitHub username across all repositories and files using the GitHub API. Supports dry-run mode, rate limit handling, and smart commits.
Install / Use
/learn @SafwanGanz/GitRebrandREADME
🚀 GitHub Username Auto-Updater
A powerful, CLI tool that automatically finds and replaces your old GitHub username with a new one across all your repositories and files using the GitHub REST API.
✨ Features
- 🔐 Secure Authentication - Uses GitHub Personal Access Tokens
- 🔄 Automated Updates - Updates all occurrences across all repositories
- 📝 Smart File Detection - Targets
.md,.json,.js,.ts,.yml,.html,.css, and more - 🎨 Beautiful CLI - Colorful output with progress spinners
- 🛡️ Safe & Dry-run Mode - Preview changes before applying
- ⏱️ Rate Limit Handling - Intelligent delays to avoid API limits
- 📊 Detailed Statistics - See exactly what changed
- 🎯 Selective Processing - Skips binary files and archived repos
- 💾 Auto Commits - Creates meaningful commit messages
📋 Prerequisites
- Node.js v18.0.0 or higher
- GitHub Personal Access Token with
repoandread:userscopes
🔧 Installation
-
Clone the repository:
git clone https://github.com/SafwanGanz/GitRebrand.git cd GitRebrand -
Install dependencies:
npm install -
Create a GitHub Personal Access Token:
- Go to GitHub Settings → Developer settings → Personal access tokens
- Click "Generate new token (classic)"
- Select scopes:
repo(Full control of private repositories) andread:user - Copy the generated token
-
Configure environment variables:
# Copy the example .env file cp .env .env.localEdit
.envand add your token:GITHUB_TOKEN=ghp_your_token_here OLD_USERNAME=your-old-username NEW_USERNAME=your-new-username
🚀 Usage
Basic Usage
node index.js --old oldUsername --new newUsername --token ghp_xxxxx
Dry Run (Recommended First!)
Preview what would change without making any commits:
node index.js --old oldUsername --new newUsername --token ghp_xxxxx --dry-run
Using Environment Variables
If you've set values in .env, you can simply run:
node index.js
CLI Options
| Option | Alias | Description | Required |
|--------|-------|-------------|----------|
| --old | -o | Old GitHub username | Yes |
| --new | -n | New GitHub username | Yes |
| --token | -t | GitHub personal access token | Yes |
| --dry-run | -d | Preview changes without committing | No |
| --help | -h | Show help message | No |
📁 Project Structure
github-username-updater/
├── index.js # Main CLI application
├── utils/
│ ├── api.js # GitHub API wrapper with rate limiting
│ ├── replacer.js # Text replacement logic
│ ├── logger.js # Colorful console logger
├── .env # Environment variables (create this)
├── .gitignore # Git ignore file
├── package.json # Project dependencies
└── README.md # Documentation
🎯 How It Works
- Authentication - Verifies your GitHub token
- Fetch Repositories - Gets all your repositories
- Scan Files - For each repo, scans all files recursively
- Filter Files - Processes only text-based files (
.md,.json,.js, etc.) - Replace Text - Finds and replaces old username with new username
- Commit Changes - Creates commits with message:
chore: updated username from oldUsername to newUsername - Rate Limiting - Waits 1.5 seconds between repos to respect GitHub API limits
📊 Example Output
🚀 GitHub Username Auto-Updater
⚠ Running in DRY-RUN mode - no changes will be committed
✓ Authenticated as yourname
ℹ Replacing: olduser → newuser
✓ Found 25 repositories
────────────────────────────────────────────────────────
[1/25] safwanganz/GitRebrand
────────────────────────────────────────────────────────
➜ README.md (3 replacements)
➜ package.json (2 replacements)
○ index.js (no changes)
ℹ Would commit 2 file(s) (dry-run)
────────────────────────────────────────────────────────
📊 Summary:
Total repositories: 25
✓ Updated: 18
⚠ Skipped: 5
✗ Failed: 2
📝 Total files changed: 47
🔄 Total replacements: 156
────────────────────────────────────────────────────────
🛡️ Safety Features
- ✅ Dry-run mode - Test before applying changes
- ✅ Skips binary files - Only processes text files
- ✅ Skips archived repos - Won't modify archived repositories
- ✅ Rate limit protection - Automatic retry with exponential backoff
- ✅ Case-sensitive matching - Prevents false positives
- ✅ Username validation - Checks GitHub username format
🧪 Testing Safely
⚠️ IMPORTANT: Always test with dry-run first!
-
First, run in dry-run mode:
node index.js --old testuser --new newuser --token ghp_xxx --dry-run -
Review the output carefully - Check which files would be changed
-
Test on a single repository first:
- Create a test repository
- Run the tool on just that repo (you could modify the code temporarily)
-
When confident, run without dry-run:
node index.js --old testuser --new newuser --token ghp_xxx -
Verify changes on GitHub - Check a few repositories manually
🔍 Supported File Types
- Markdown:
.md - JavaScript/TypeScript:
.js,.ts,.jsx,.tsx - JSON:
.json - YAML:
.yml,.yaml - HTML/CSS:
.html,.css - Configuration:
.env,.gitignore,.npmrc - Shell scripts:
.sh - Text files:
.txt - Files without extension:
README,LICENSE,CHANGELOG
⚙️ Configuration
Rate Limiting
Default delay between repository updates: 1.5 seconds
To modify, edit utils/api.js:
this.rateLimitDelay = 1500; // milliseconds
File Types
To add more file types, edit utils/replacer.js:
const targetExtensions = [
'.md', '.json', '.js', '.ts',
'.your-new-extension' // Add here
];
🐛 Troubleshooting
"Authentication failed"
- Verify your token is correct
- Ensure token has
repoandread:userscopes
"Rate limit exceeded"
- The tool will automatically wait and retry
- Consider increasing
rateLimitDelayinutils/api.js
"Invalid username format"
- GitHub usernames: alphanumeric + hyphens, max 39 characters
- Cannot start/end with hyphen
No files being updated
- Check if your username actually appears in the files
- Verify file types are supported
- Run with
--dry-runto see what would be processed
📝 License
MIT License - feel free to use this in your own projects!
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request to SafwanGanz/GitRebrand.
⚠️ Disclaimer
This tool makes automated changes to your repositories. Always:
- ✅ Use
--dry-runfirst - ✅ Have backups of important repositories
- ✅ Review changes before running
- ✅ Test on non-critical repos first
📚 Resources
💡 Tips
- Backup Important Repos - Clone locally before running
- Start Small - Test on a few repos first
- Check Commit History - Verify commits look correct
- Update Local Clones - Pull changes after running the tool
Made with ❤️ by developers, for developers
If you find this tool helpful, please give it a ⭐️!
Related Skills
apple-reminders
350.8kManage Apple Reminders via remindctl CLI (list, add, edit, complete, delete). Supports lists, date filters, and JSON/plain output.
gh-issues
350.8kFetch GitHub issues, spawn sub-agents to implement fixes and open PRs, then monitor and address PR review comments. Usage: /gh-issues [owner/repo] [--label bug] [--limit 5] [--milestone v1.0] [--assignee @me] [--fork user/repo] [--watch] [--interval 5] [--reviews-only] [--cron] [--dry-run] [--model glm-5] [--notify-channel -1002381931352]
oracle
350.8kBest practices for using the oracle CLI (prompt + file bundling, engines, sessions, and file attachment patterns).
xurl
350.8kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
