0

So I have multiple GitHub accounts and I really want to be able to change GitHub accounts in Git on my computer. Does anyone know how to do this?

When I try to push to my other account, I get this error: remote: Permission to denied to . fatal: unable to access <'my repo'>: The requested URL returned error: 403

Thanks.

1615903
  • 25,960
  • 9
  • 55
  • 82
Spyke
  • 23
  • 4
  • As [e.doroskevic said](http://stackoverflow.com/a/38818090/1256452), you need—or your Git needs—to *authenticate* to the server. Authentication is a side issue for Git: Git leaves it to other programs. Exactly *which* programs, depends on whether you push with `https://` or `ssh://`, and also on whether you're on Windows, MacOS, or a Unix-like system. So you should probably specify your OS. (The "error 403" demonstrates that you're using `https://`.) – torek Aug 07 '16 at 20:53
  • I'm running windows 10 on https:// – Spyke Aug 07 '16 at 21:19

2 Answers2

0

Normally, when you do git push [-u] <remote> <branch>, git system will require you to authanticate by providing the username and password of your Git Hub account.

So, say I have cloned a remote repository from account01

git clone <url>

I do some work (add, modify, delete some files) and then I do

git add .
git commit -m "commit message"

Now, when I push

git push -u <upstream_name> <branch>

Note : -u for upstream (I may be wrong!)

git will ask me to provide my account details in a form of username and password. After I have provided git with this information, the push instruction will commence.

EDIT 1

If you are trying to push to a remote repoistory located on account01 from account02, you may need to configure Collaborators on a remote repository located at account01. Simply

  1. Log in with your account
  2. Click on the remote repository you want to allow collaboration on
  3. Click on Settings
  4. Click on Collaborators
  5. Write your account02 username
  6. Click Add collaborator
  7. Go to your email address which you used to create account02
  8. Accept collaboration request

At this point you will be able push directly to this remote repository from account02

e.doroskevic
  • 1,969
  • 14
  • 25
  • For some reason mine is saved and I don't get prompted to login. Is there a way to fix that? Thanks a lot. – Spyke Aug 07 '16 at 20:19
  • How do you push? Can you provide the instructions you pass on to git? – e.doroskevic Aug 07 '16 at 20:22
  • Ok that makes sense. Thank you very much I appreciate it! That was super helpful and I'm glad this problem could be solved. – Spyke Aug 07 '16 at 20:27
  • 1
    The `-u` flag on `git push` is shorthand for "set upstream": it means that *if the push succeeds*, Git should subsequently run `git branch --set-upstream-to` for you. You can of course do this yourself instead, so `-u` is never technically required. See http://stackoverflow.com/q/6089294/1256452 and/or http://stackoverflow.com/q/37770467/1256452 – torek Aug 07 '16 at 20:50
0

Before pushing go to credential manager, than windows credential and delete personel access token of github and now you can push using different github account.