'How to change git repository using android studio

I'm using git with android studio and I already sync other repository.

But I hope to change a git repository like github.

I think I need to disconnect already connected to the repository but I don't found this option.

To do that, How can I do?



Solution 1:[1]

Go to your project directory and delete hidding .git folder like shown below

you will be disconnected to git.

enter image description here

Solution 2:[2]

We can change the repository url. Just follow the steps.

In Android Studio Arctic Fox | 2020.3.1

  1. Right click on project folder
  2. From menu Choose “Git”
  3. Then chosse "Manage Remotes..."
  4. Now, select the existing "origin" and click on edit
  5. Enter your new URL and click OK

For Android Studio Older versions

  1. Right click on project folder
  2. From menu Choose “Git
  3. Choose “Repository
  4. Choose “Remotes…”

Git > Repository > Remotes...

  1. Now you got the “Git Remotes” popup

Git Remotes

  1. You can edit the existing url or remove the old url and then add new url.
  2. Click “OK”. that’s it. Now you are connected with new repo. But branches are not connected. Just follow few steps to complete.
  3. Try to pull the changes from repo “Git > Repository > Pull…
  4. Now you got the “Pull Changes” popup. Click “Refresh” button.

Pull Changes

  1. After successfully reconnected with repo then you can see the branches of new repo under “Branches to merge” box.

Branches to merge

  1. Done. Now you are connected with new repo & branches.

Happy Coding :)

Solution 3:[3]

You can use SmartGit application and set your new git url at "Remote\Properties..." and then push button "Store".

Or you can go to "[project folder]\.git" and edit "config" file. Find line "url = https//[your current url]" and put your new url instead.

Solution 4:[4]

2021 method

Tested on Android Studio Arctic Fox | 2020.3.1

  1. Right click on project folder
  2. From menu Choose “Git”
  3. Then chosse "Manage Remotes..."
  4. Now, select the existing "origin" and click on edit
  5. Enter your new URL and click ok

Solution 5:[5]

All answers above is okay, but after changing a remote url you want to make a new commit with all old files, yes? How to do it I made the video, see https://youtu.be/_ffZXwgA5oU

I just created a new Android Studio project and initialized a new git folder with new remote url repository, and then I just copied and paste all files from old project to new, see https://youtu.be/_ffZXwgA5oU

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Noor Nawaz
Solution 2
Solution 3 Evgeny Sinitsky
Solution 4 Kaaveh Mohamedi
Solution 5 Dyno Cris