Reputation: 643
I'm trying to share a project on GitHub and want to use IntelliJ IDEA's built-in "Share project on GitHub" option. When I click on it, I am asked to log in to GitHub, which I do successfully, and then choose the files I want to commit so that they can be pushed to the repository.
The problem is that, while this does indeed create an empty repository on GitHub, it doesn't push the initial commit, and instead throws an error at me:
Successfully created project 'project' on GitHub, but initial push failed: unable to access 'https://github.com/alt/project.git/': The requested URL returned error: 403
I know the reason it does this is because I set up git to use my main account, and I'm trying to push to the repository which is on my alt account. I set up an alt account for my own reasons. After this failed, I tried to do it using git bash; I generated a new ssh keypair for the alt account and added it to the SSH keys in the alt account on GitHub. I also created a config in my ~/.ssh/
folder:
#Default GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
#Alt GitHub
Host github-alt
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_alt
And also set the user.email and user.name to the email and name of my alt account. After doing all of this, I then tried to add a new remote and push it using git bash:
git remote add origin git@github-alt:alt/project.git
git push -u origin master
Which does actually push the commit to the repository... as my main account, not my alt account.
What am I doing wrong here? I want to share a project on GitHub on my alt account, and push commits to it using the same alt account.
Upvotes: 1
Views: 138
Reputation: 1049
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="[email protected]"
NEW_NAME="alt"
NEW_EMAIL="[email protected]"
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/*'
Upvotes: 2