2

I previously used git bash for local repository.
I have connected to a GitHub account and I always pushed my files without any problem.
Later, I have uninstall the bash and reinstall again with new user and email. Now when I try to push the file to remote I got an error:

 Permission to SyedMiraj/SpringSecurityWithTicketBooking.git denied to biid-sua.
 unable to access 'https://github.com/SyedMiraj/SpringSecurityWithTicketBooking.git/': The requested URL returned error: 403

I have tried and created a new SSH key and add it in the remote repo.
But the problem is still existing and truly speaking I can't push anything to my remote.
My two GitHub accounts are biid-sua and smiraj.

How would you propose to restore GitHub pushes?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Shahriar Miraj
  • 307
  • 3
  • 14

2 Answers2

4

A couple of points here:

  • the user and email used to make commits have nothing to do with the remote repo (here hosted on GitHub) for authentication
  • SSH keys (old or new) are not used at all when pushing to GitHub with an https URL.
    If it uses your first biid-sua account, this is because of a git credential helper, that has cached your biid-sua credentials for github.com.

You can either make sure and delete that entry (either on Mac or on Windows). You will be prompt for your new username/password at the next push.

Or you can swtich to an SSH URL:

cd /path/to/my/local/repo
git remote set-url origin g2:SyedMiraj/SpringSecurityWithTicketBooking.git

And then make sure your ~/.ssh/config defines the g2 entry and references the right key (as I explain here)

#Account one
Host g1
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile /c/Users/yourname/.ssh/id_rsa_biid-sua
    User git

#Account two
Host g2
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile /c/Users/yourname/.ssh/id_rsa_smiraj
    User git

Assuming that you have name your SSH keys in HOME:

  • .ssh/id_rsa_biid-sua and .ssh/id_rsa_biid-sua.pub
  • .ssh/id_rsa_smiraj and .ssh/id_rsa_smiraj.pub
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • ~/.ssh/config , how to use this path on window?, where this config file should be created? –  Apr 15 '23 at 12:04
  • @KarthikKumar `~` will by default fall back to `%USERPROFILE%`. So you can create the config file as `%USERPROFILE%\.ssh\config`. – VonC Apr 15 '23 at 16:22
-1

you need to change your repo config on your PC to ssh way: refer

ntshetty
  • 1,293
  • 9
  • 20