A bash script to migrate GitHub repositories from one account to another while preserving complete commit history. This is particularly useful when migrating your GitHub profile and you want to maintain your contribution graph.
- Clones the entire repository history (including all branches and tags) from your old GitHub account
- Pushes everything to your new GitHub account
- Shows you which email addresses are associated with commits
- Provides step-by-step guidance for completing the migration
- Preserves your contribution graph by migrating commit history
Before using this script, make sure you have:
- Git installed on your system
- SSH key configured for your new GitHub account
- GitHub Personal Access Token for your old account (with
repopermissions) - Both repositories created:
- The repository exists in your old account
- An empty repository exists in your new account
- Go to your old GitHub account → Settings → Developer settings → Personal access tokens → Tokens (classic)
- Click "Generate new token (classic)"
- Give it a descriptive name (e.g., "Repository Migration")
- Select the
reposcope (full control of private repositories) - Click "Generate token"
- Copy the token immediately (you won't be able to see it again!)
git clone https://github.com/YOUR_USERNAME/github-profile-migrator.git
cd github-profile-migratorOr download the script files directly.
Available scripts:
migrate_repo.sh- Non-interactive version (only asks for initial confirmation)migrate_repo_interactive.sh- Fully interactive version (asks for confirmation at each step)
After cloning or downloading, you need to give execute permissions to the script:
chmod +x migrate_repo.shOr if using the interactive version:
chmod +x migrate_repo_interactive.shOpen the script file (migrate_repo.sh or migrate_repo_interactive.sh) in your favorite editor and fill in the configuration section at the top:
# ===== CONFIG =====
OLD_USER="your-old-username" # Your old GitHub username
NEW_USER="your-new-username" # Your new GitHub username
REPO_NAME="repository-name" # Name of the repository to migrate
SOURCE_GITHUB_TOKEN="ghp_your_token_here" # Your GitHub Personal Access Token
# ==================Example:
OLD_USER="oldaccount"
NEW_USER="newaccount"
REPO_NAME="my-awesome-project"
SOURCE_GITHUB_TOKEN="ghp_some-token-generated"- Log in to your new GitHub account
- Create a new repository with the same name (or the name you want)
- Do NOT initialize it with a README, .gitignore, or license (keep it empty)
- Make sure your SSH key is added to your new GitHub account
For non-interactive version:
./migrate_repo.shFor interactive version:
./migrate_repo_interactive.shThe script will:
- Show you the configuration and ask for confirmation (non-interactive version only asks once)
- Check if both repositories exist and are accessible
- Clone the repository with full history
- Show you the email addresses used in commits
- Push everything to your new repository
The interactive version will ask for confirmation at each step, while the non-interactive version proceeds automatically after the initial confirmation.
After the repository migration, you must migrate the email addresses associated with your commits. GitHub uses email addresses in commits to attribute contributions to your profile. If the email addresses aren't verified on your new account, those commits won't show up in your contribution graph.
- Note the email addresses shown by the script during migration
- Remove emails from old account:
- Go to old account → Settings → Emails
- Remove the email addresses that were used in commits
- Add emails to new account:
- Go to new account → Settings → Emails
- Add the same email addresses
- Verify them (check your inbox for verification emails)
- Wait a few minutes for GitHub to update your contribution graph (Subjective for some repos the contribution did not reflect yet)
- Verify that your commits appear on your new profile
- Only delete your old account after verifying that commits appear on your new profile
- This process can take a few minutes to a few hours for GitHub to update
- If you have multiple repositories, you'll need to run this script for each one
- Verify the repository name is correct
- Check that your token has
repopermissions - Ensure the token hasn't expired
- Make sure you've created the repository in your new account
- Verify your SSH key is added to your new GitHub account
- Test SSH connection:
ssh -T git@github.com
- Check that your SSH key is properly configured
- Verify the repository name matches exactly
- Ensure you have write access to the new repository
- Make sure you've added and verified the email addresses on your new account
- Wait a few hours for GitHub to update
- Check that the email addresses match exactly (case-sensitive)
# 1. Clone the repository
git clone https://github.com/YOUR_USERNAME/github-profile-migrator.git
cd github-profile-migrator
# 2. Make the script executable
chmod +x migrate_repo.sh
# 3. Configure the script
vim migrate_repo.sh
# Edit OLD_USER, NEW_USER, REPO_NAME, SOURCE_GITHUB_TOKEN
# 4. Run the migration
./migrate_repo.sh
# 5. Follow the prompt (non-interactive version):
# - Confirm settings: y
# Then it proceeds automatically
# For interactive version (migrate_repo_interactive.sh):
# - Confirm settings: y
# - Proceed with migration: y
# - Clone repository: y
# - Push to new account: y
# 6. Complete email migration (see instructions above)Contributions are welcome! Feel free to:
- Report bugs
- Suggest improvements
- Submit pull requests
This script is provided as-is for public use. Use at your own risk.
This script migrates repositories and commit history. Always:
- Test on a non-critical repository first
- Keep backups of important repositories
- Verify the migration before deleting your old account
- Understand that you're responsible for your own data