Nitish Srivastava
Nitish Srivastava

Reputation: 449

Change Github account in Android Studio

I have used one Github account to push an android project to Github from Android Studio. Now I have created another account on Github and want to push my another android project to this new account. But I am not able to find any option to change the Github account in Android Studio. It keeps pushing from the previous account and hence results in this error:

remote: Permission to new_username/repository_name.git denied to old_username.

fatal: unable to access 'https://github.com/new_username/repository_name.git/': The requested URL returned error: 403

I am using Android Studio 1.2.2 on Windows OS.

Upvotes: 44

Views: 118988

Answers (14)

genericUser
genericUser

Reputation: 7188

Edit GitHub Accouts

You can add / remove / replace GitHub accounts on Preferences -> Virsion Control -> GitHub.

enter image description here

If you have generated a new access token, consider removing the deprecated user, and adding the new one using "Log In with token":

enter image description here

Upvotes: 0

Tanmay Agarwal
Tanmay Agarwal

Reputation: 506

I tried all methods, mentioned in all answers, but nothing works, but now I finally found the solution of this problem after stuggling from 1 week, so simply the issue is occuring because in window there is credential manager which is storing your old github credential, so simple steps to solve this issue are :-

step 1) Search Credential Manager enter image description here

step 2) click here on Windows credentials enter image description here

step 3) Delete your old github credentials enter image description here

step 4) You are good to go, simply go to android studio and commit and push your code on github using terminal then it will automatically ask your to login to github then click on login via token using github token, then you are good to go :)

Hope this solutions solves everyone github issue :)

Upvotes: 5

Sunil
Sunil

Reputation: 3504

Go VCS>Commit and you will see Author field as shown:

enter image description here

Change author email Id

Upvotes: 0

Nikesh Maharjan
Nikesh Maharjan

Reputation: 183

I solved mine with re-installing,

git credential-manager uninstall then git credential-manager install push to repo git push --set-upstream origin master this will ask for authentication, authenticate and BoooMMMM!!!

Upvotes: 1

Febin K R
Febin K R

Reputation: 996

Uncheck the Use Credentials Helper from Settings -> Version Control -> Git. Then log in using the desired account and select the account you want to continue with from Settings -> Version Control -> GitHub.

 How to Uncheck use credentials helper

Upvotes: 29

adrianekafikri
adrianekafikri

Reputation: 368

I had the same problem and had solved it.
With current Android Studio 3.5 we can add several github account

enter image description here

with several github account added we can select one for the default for specific project.

or

change the git username and email:

  • git config user.name "your username"
  • git config user.email "youremail.com"


add --global if you want change for global config

Upvotes: 11

Raju Ugale
Raju Ugale

Reputation: 4291

I was also facing the same issue (working on same PC with diff usernames)

remote: Permission to new_username/repository_name.git denied to old_username.

Tried all solution mentioned even deleting .gitconfig didn't work.

In the end, solved by following different way :
1. Adding as Collaborator to old_username
2. Accept collaboration invitation (Make sure you are logged in to old_username)
3. Push with new_username. Done!

Upvotes: 0

Hiren Patel
Hiren Patel

Reputation: 52800

In my case none of working. This way works for me.

Steps:

  1. Open Settings of Android studio
  2. Select Appearance & Behavior
  3. Select System Settings
  4. Select Passwords
  5. Select Do not remember passwords
  6. Click on OK

Now its time to Push your source code to Git, Android studio would ask for new username and its password.

Reference screenshot.

enter image description here

Done

Upvotes: 14

ADEBAYO OSIPITAN
ADEBAYO OSIPITAN

Reputation: 68

You need to first go to: Setting --> Version Control --> GitHub --> Change you username. (just like Nir Duan) said.

Then go to: VCS --> Checkout of Version Control --> Github

Log in with new credentials if asked, Change the Git URL and possibly parent directory, Click on clone, open in another window, wait for it to load. close the new window.

Next time you want to push you will see the new repository as part of the options at the top left on the "Push commit" pop-up

Upvotes: 0

kyshel
kyshel

Reputation: 602

Step 1

Change file config in directory .git that located in your project folder

lala

Step 2

In terminal @ current project, type:
git credential-manager uninstall

Cheers~

Upvotes: 29

Wallace Zhen
Wallace Zhen

Reputation: 175

I had the same problem, all you need to do is open your shell and type--

$git config --global user.name [your username]
$git config --global user.email [your email]

since you probably logged in with git using a different account

Upvotes: 1

Marl Ene
Marl Ene

Reputation: 24

When prompted for a username and password, make sure you use an account that has access to the repository.

And in the image of Nir Duan, you must click to the button "test" to verify your connection.

Upvotes: 1

Nir Duan
Nir Duan

Reputation: 6392

Go to:
Setting --> Version Control --> GitHub --> Change you username.

enter image description here

Upvotes: 39

jedifans
jedifans

Reputation: 2297

Perhaps not the answer you are wanting, but you can probably solve this by finding out where the project code is stored by android studio and changing the git remote there.

For example, if you want to change where the main repository you push to, enter this in the command line when inside the project directory: git remote set-url origin <new-url-from-github>

Upvotes: 4

Related Questions