Graeme Benzie Graeme Benzie - 27 days ago 7
Git Question

Need to switch from personal to work git account

I have have been using my personal git and github accounts on my work computer Windows10 but would like to start using work accounts instead.

I have created a new work account and repository on github. After cloning the repository to my local machine, making a commit and then trying to push I get the following error.

git push
To https://github.com/workuser/workrepo.git
! [remote rejected] release -> release (permission denied)
error: failed to push some refs to
'https://github.com/workuser/workrepo.git'


I am using VS Code

If I run

git config --get user.email


I get my work email

Within the terminal in VS Code

git remote -v
origin https://github.com/workuser/workrepo.git (fetch)
origin https://github.com/workuser/workrepo.git (push)


What do I need to do so I can push to my work repo on github

Thanks

Answer Source

You tried to push to the https link of your repo and that won't work (without manually typing your username and password). You have to use the ssh version of the link!

To change the link for the remote origin open a console in the directory of your repo and type:

git remote set-url origin git@github.com:workuser/workrepo.git

Now you should be able to push to github.