2

I've been trying to push my Android Studio project to github for some time now.

If I go into settings->Version Control->Git and hit "Test", it says it's fine

If I go into settings->Version Control->Github and hit "Test" with my Github credentials, it says everything is fine.

But when I go to VCS->Import into Version Control->Share project on Github, it will create the project on Github and commit the changes to the local repo, but won't push any of the changes. it always says:

Push failed: Failed with error: unable to access 'https://github.com/myusername/project.git/': The requested URL returned error: 403

(where "myusername" and "project" are my specific details, of course)

I've already uninstalled and reinstalled git multiple times, I've checked and my global user.name and user.email are correct. I can't figure out what else I can possibly do to get this working.

1
  • Have you activated 2 step verification in GitHub? Commented Dec 10, 2017 at 22:10

4 Answers 4

3

You have to create a remote repo on the Github then push your local repo.

There doesn't seem to be a way to add a remote through the GUI in Android Studio. So open Git Bash (Terminal in Android Studio) in the root of the project and do git remote add

Now when you do VCS -> Commit changes -> Commit & Push. You should see your commit reflected on the github.

Sign up to request clarification or add additional context in comments.

4 Comments

Doing that gives me this message: usage: git remote add [<options>] <name> <url> -f, --fetch fetch the remote branches --tags import all tags and associated objects when fetching or do not fetch any tag at all (--no-tags) -t, --track <branch> branch(es) to track -m, --master <branch> master branch --mirror[=<push|fetch>] set up remote as a mirror to push to or fetch from
ok, so I tried "git remote add origin github.com/myusername/project.git" and it says "fatal: remote origin already exists" So I'm guessing that I already have the remote repo
Alright, using the Github Desktop application, I was able to make it work. I'm not sure if this is just a workaround for an underlying issue, but it'll work for the time being. Thanks for the help
I have pushed a project to github from my android studio and it works. if you have the remote repo already then you should be able to just commit and push from the Android Studio. If you think my answer helped you solve the issue, then you can mark the question as answered.
2

I know It's too late to answer but I want to add more information about solving this problem because the above answer didn't help me so I figure it out somewhere else.

When you get a 403 on this challenge it is because you are trying to push your changes to a repository you don't have access to. It happens when you saved your github credential with another account and want to share project into another account repository.

I had this problem too but managed to solve it, the error is that ur computer has saved a git username and password so if you shift to another account the error 403 will appear. Below is the solution For Windows you can find the keys here:

control panel > user accounts > credential manager > Windows credentials > Generic credentials

Next remove the Github keys.

Afther that Enter the command

git push -u origin master

or

click on VCS > Git > Push.

Comments

1

Generate a login token...

On Android Studio (2021.2.1) I was able to push by going to File->Settings->Version Control->GitHub and then push the "plus icon" to add an account. Add account dialog shows up. Press "Generate..." button. Log in to GitHub. Generates the token. Copy the token code and paste into the Android Studio login dialog.

You may need to close the project in Android Studio and then reload the project for git settings to be updated.

Possibly going to File->Settings->Version Control->Git and then checking the box labeled "Use credential helper" is necessary.

Authorize Git Credential Manager is ankther option that has appeared for me.

Comments

0

I ran into the same problem today. Probable cause: I have a local repository with the same name as a robot class in another repository. I renamed the wrongly named repo, kept the robot class name in the other repo, then pushed. No gripes.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.