2

I have two git hub accounts. I am Windows user and I use git bash as the client.I am working on a project. I can push my project to first github account. But when I try to push second one it says there is no permission.

$ git push -u origin master
remote: Permission to <secondUser>/<repo>.git denied to <firstUser>.
fatal: unable to access 'https://github.com/<secondUser>/<repo>.git/': The requested URL returned error: 403

Can any one suggest a way to push the project to second account.

2 Answers2

2

You should use the ssh key. In the config file(usually ~/.ssh/config) you can define multiple alias for multiple accounts like this(for instance in Linux):

Host first_name 
HostName github.com
User git
IdentityFile ~/.ssh/key_for_first_name

Host second_name 
HostName github.com
User git
IdentityFile ~/.ssh/key_for_second_name

Under the directory of the repository in ./.git/config you can set like this:

[remote "first_account"]
    url = git@first_name:[your_first_github_name]/[repository_name].git
    fetch = +refs/heads/*:refs/remotes/first_name/*
[remote "second_account"]
    url = git@second_name:[your_second_github_name]/[repository_name].git
    fetch = +refs/heads/*:refs/remotes/second_name/*

While pushing you can do this:

git push first_account master:master
git push second_account master:second_master

You can apply this mechanism to the windows scenario. Hope this helps.

Lerner Zhang
  • 6,184
  • 2
  • 49
  • 66
0

Generate SSH key on your pc, add this ssh key in your both account. Then it works fine.

Sandip Kumar
  • 129
  • 2
  • 11