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.
- π 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
- Node.js v18.0.0 or higher
- GitHub Personal Access Token with
repoandread:userscopes
-
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
node index.js --old oldUsername --new newUsername --token ghp_xxxxxPreview what would change without making any commits:
node index.js --old oldUsername --new newUsername --token ghp_xxxxx --dry-runIf you've set values in .env, you can simply run:
node index.js| 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 |
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
- 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
π 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
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- β 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
-
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
- 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
Default delay between repository updates: 1.5 seconds
To modify, edit utils/api.js:
this.rateLimitDelay = 1500; // millisecondsTo add more file types, edit utils/replacer.js:
const targetExtensions = [
'.md', '.json', '.js', '.ts',
'.your-new-extension' // Add here
];- Verify your token is correct
- Ensure token has
repoandread:userscopes
- The tool will automatically wait and retry
- Consider increasing
rateLimitDelayinutils/api.js
- GitHub usernames: alphanumeric + hyphens, max 39 characters
- Cannot start/end with hyphen
- Check if your username actually appears in the files
- Verify file types are supported
- Run with
--dry-runto see what would be processed
MIT License - feel free to use this in your own projects!
Contributions are welcome! Please feel free to submit a Pull Request to SafwanGanz/GitRebrand.
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
- 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 βοΈ!