Change Github account in Android Studio - android

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.

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

Step 1
Change file config in directory .git that located in your project folder
Step 2
In terminal # current project, type:
git credential-manager uninstall
Cheers~

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.

In my case none of working. This way works for me.
Steps:
Open Settings of Android studio
Select Appearance & Behavior
Select System Settings
Select Passwords
Select Do not remember passwords
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.
Done

I had the same problem and had solved it.
With current Android Studio 3.5 we can add several github account
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

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>

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
step 2) click here on Windows credentials
step 3) Delete your old github credentials
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 :)

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.

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

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!!!

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

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!

Go VCS>Commit and you will see Author field as shown:
Change author email Id

Edit GitHub Accouts
You can add / remove / replace GitHub accounts on Preferences -> Virsion Control -> GitHub.
If you have generated a new access token, consider removing the deprecated user, and adding the new one using "Log In with token":

Related

amplify init fails constantly

I don't know whats really wrong with my amplify. I run amplify init and get this error message. I have downloaded my amplify cli using npm and have successfully run 'amplify configure'.
init failed
InvalidSignatureException: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
The Canonical String for this request should have been
'POST
/apps
host:amplify.ap-south-1.amazonaws.com
x-amz-content-sha256:79ec4b759220a7b1d454721bb2c7e1350dccbd691853e5ed1b3c92bec21dbc29
x-amz-date:20210121T154050Z
host;x-amz-content-sha256;x-amz-date
79ec4b759220a7b1d454721bb2c7e1350dccbd691853e5ed1b3c92bec21dbc29'
The String-to-Sign should have been
'AWS4-HMAC-SHA256
20210121T154050Z
20210121/ap-south-1/amplify/aws4_request
b150344845c2c575fd957d63172173a367f2bacf0e817764a02e5b20d03c3811'
Okay, so I finally found out what was bugging me for last three days. A whitespace ( ).
Yes!
I had my folder inside the user with a whitespace in it, as in "First Last". Instead what I should have done is changed my folder name inside my C:\Users\First Last to C:\Users\FirstLast before starting, and then try to install my amplify CLI using the command curl -sL https://aws-amplify.github.io/amplify-cli/install-win -o install.cmd && install.cmd and proceed as mentioned in the documentation here.
To change the name of the User folder in windows 10, I watched this great YT! video
On Mac:
I was also getting the same error while using the aws amplify CLI tool in my nodejs project.
Like #miraquee noted above about the issue being a white space. I suspected that I also had the same issue. What I did to start clean was:
Delete the local .aws folder in my home folder on mac to start clean
rm -rf ~/.aws/
Ran amplify init again. This time when reaching the step where it asks you to create an IAM user, which subsequently takes opens your web browser to finish the creation of the new IAM user, I was very careful about copying in the Access Key Id and Secret Access Key
This time when I went through the flow in the CLI it worked.
If you want to see a video of these steps, checkout this YouTube video built by one of the engineers on the AWS amplify team
Youtube video link: https://www.youtube.com/watch?v=fWbM5DLh25U

Cant push into github from android studio

I can add my projects to one github account but with another account i can't. I have followed this website for GitHub and worked fine: https://www.londonappdeveloper.com/how-to-use-git-hub-with-android-studio/#comment-32683
Steps are: 1. create a new git repo. 2. from android studio- VCS> Import into version control> create git repo. 3. In windows root directory of project open bash command and type > git remote add origin https://github.com/xxx/myProject.git 4. then back to android studio and a)project>Git>add b)project>Git>Commit c) project>Git>repository>push
these steps worked fine and I get a successful message using one github account. But with another account i cant do it, i get the erro:
Failed with error: fatal: unable to access 'https://github.com/Rashedul/myProject.git/': The requested URL returned error: 403
Why is this happening and how to solve it?
First you should set username and password to access the URL and to login , set Authentication first.
git remote set-url origin https://yourusername#github.com/user/repo.git
Then you'll be asked for a password when trying to git push
This is on the http authentication format. You could set a password also:
https://youruser:password#github.com/user/repo.git
You should be aware that if you do this, your github password will be stored in plaintext in your .git directory, which is obviously undesirable.

Why _mac folder with some config files commits to git automatically from Android Studio

I am getting some auto generated commits to my git using android studio in mac and this was not happened in windows with Android studio(Which I was using earlier) Can anyone tell me why this happens and how to disable it?
The commits starts with AI-2.3.2 its my android studio verion
below is my global gitconfig file
[core]
excludesfile = /Users/User/.gitignore_global
[difftool "sourcetree"]
cmd = opendiff \"$LOCAL\" \"$REMOTE\"
path =
[mergetool "sourcetree"]
cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
trustExitCode = true
[user]
name = Test
email = test#gmail.com
[commit]
template = /Users/User/.stCommitMsg
FIX: Open Preferences → Tools → Settings Repository → Delete. I also disabled Auto-Sync. Dunno where it's going to save if I delete everything, but I switch it off to be extra safe..
I just ran into this. Turns out this feature is called "Settings Repository", and it's intended to save IDE settings automatically. I guess I might accidentally agree on some popup from IDEA which look like add files to the git repository, so this started working.

Android-Studio git over ssh

I got a git-server on my Raspberry Pi with gitweb as webinterface.
Its working so far.
Now I want to connect via Android Studio with the built-in ssh to it.
My project dir is :
/home/git/straff.git
I'll connect with this command from Android Studio:
:ssh:git#192.168.178.21:/straff
Android Studio is giving me this when I test the connection:
Cannot access /straff/CVSROOT
I am using password auth for it. I can access from command line tools to my repo...
Why Android Studio cant?
I can access from command line tools to my repo...
Why Android Studio cant?
Your error is you are trying to access 192.168.178.21:/straff which is /straff on that machine. Either provide the full path like below or use this one
:ssh:git#192.168.178.21:straff
Old post:
You can try to specify the full path to Android Studio:
:ssh:git#192.168.178.21:/home/git/straff
I am using password auth for it.
That means the ssh connection doesn't use a private/public (~/.ssh/id_rsa(.pub)) key.
A good tutorial to follow with Android Studio is the one titled "How to push to a remote Git repository over SSH with private/public key authentication using Android Studio".
Hmm, should the URL be like:
ssh://git#192.168.178.21/straff
I had problems with setting ssh key. I solved it by creating id_rsa -titled file under .ssh-directory (under user home-dir) and putting my RSA-stuff into it.
If you already have the remote git repository, which you want to check out, and you have a private key, then the instructions on https://www.londonappdeveloper.com/how-to-push-to-a-remote-git-repository-over-ssh-with-privatepublic-key-authentication-using-android-studio/ might help to some extent, but they are for older version of Android Studio and they are too complicated.
What you need to do (especially when you start from scratch) is:
Ensure that your key is an OpenSSH key, and that it's a private key (not a public key). This is where the above mentioned instructions are misleading - they point to the key in supposedly Putty format (the .ppk file), and this doesn't work. If you have a Putty key, use Putty's puttygen.exe tool to export the private key in OpenSSH format.
Create the config file as described in those instructions. I.e.
create the text file named config in .ssh subdirectory of your user directory. In my case the path would be C:\Users\Eugene.ssh\config.
Put the following to this file:
Host my-host.com
HostName my-host.com
Port 22
IdentityFile C:\Users\Eugene.ssh\my-private-key-for-my-host.openssh
(the original instructions include indentation of lines 2-4, but I couldn't add any indentation here).
Use Checkout Project From Version Control menu item in Android Studio's welcome screen to initiate GIT checkout.
Use the following settings during checkout (curly brackets contain the values which you replace with yours):
Git Repository URL: {projectalias}#{my-host.com}:base/{projectname}
Parent directory: eg. "z:\Projects" The path which must exist, and in which the new project is created
Project directory: eg. "myproject". The directory with this name will be created in Parent directory, so the files will be checked out to Parent_directory\Project_directory, eg. "z:\Projects\myproject".

GitHub on Android Studio

I have a main GitHub account shared by multiple people, and we each have our own account. I created a repository through Android Studio using the main account, and now I was to push code from my personal account. So I go to the GitHub settings under File > Settings and change the login credentials to reflect my personal account. However, when I push the code it still says the commit was made by the main account, and that it is the only contributor. What am I doing wrong?
Maybe when you set up git with your new account it didn't change gitconfig
Try:
git config --global user.name "Amir"
git config --global user.email "your_email#example.com"
(note --global is optional , it will make it your name/email everywhere on the system)
Indeed, the solution by #LeonardoC solves the problem, but if you want to know why this was happening you can read this: https://help.github.com/articles/why-are-my-commits-linked-to-the-wrong-user/
Particularly, the part that says:
GitHub uses the email address in the commit header to link the commit to a GitHub user. If your commits are being linked to another user, or not linked to a user at all, you may need to change your local Git configuration settings, add an email address to your account email settings, or do both.
Note: If your commits are linked to another user, that does not mean the user can access your repository. A user can only access a repository you own if you add them as a collaborator or add them to a team that has access to the repository
So, to change your local Git configuration settings you type the two instructions aforementioned by #LeonardoC:
git config --global user.name "yourUsername"
git config --global user.email "theEmailLinkedToYourUsername"
And just in case you want to check what are the values before changing them, you can get them by just typing in the shell:
git config --global user.name
git config --global user.email

Categories

Resources