How to Share project on GitHub using alternate account

Published on Author Code Father

The command git remote add origin git@github-alt:alt/project.git && git push -u origin master pushes code to repository associated with alt account.

But this doesn’t modify author of existing commits. The commits made so far has main username associated. Changing username in entire commit history requires git history rewrite. Make sure you’ve backup of repository before doing this.

Example script:

#!/bin/sh
git filter-branch --env-filter '

OLD_EMAIL="main@sample.com"
NEW_NAME="alt"
NEW_EMAIL="alt@sample.com"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$NEW_NAME"
    export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$NEW_NAME"
    export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

Do a force push after verifying git history. git push --force --tags origin 'refs/heads/*'

Comments

comments

Categories Git