简体   繁体   中英

Remove old and add new git in android studio

I have tried to configure android studio with git and messed up.

How to completely remove old git that I could create new one?

In order to drop the current git repository and create a new one you need to:

  • Go to the project's directory: cd PROJECT_DIRECTORY

  • Remove all the git specific files: rm -rf $(find . -name ".git*")

  • Initialize a new git repository: git init

This doesn't remove your project's files, only git configs

Just a simple way

Open the terminal in android studio.

git remote set-url origin <NEW GIT URL>

now the project url is changed from old link to new one. Then you can use >

git init

and upload your files. Happy coding :)

You can remove GIT from your Android Studio Project in File → Settings → Version Control → In VCS select and Apply.

在此处输入图像描述

Then you can add it back in VSC Menu → Enable Version Control Integration → Select GIT → OK button.

在此处输入图像描述

Delete the .git folder & .gitignore and start again.

Google for how to display hidden folders on windows to see the .git folder.

In Android Studio terminal in your project dir: Windows:

rd /s /q ".git"

Linux/Mac:

rm -rf .git

If you delete a git repository from github, you should also delete a folder name .git from your Android Studio root directory.

Then you have to close the project. And re-open it in Android Studio.

Then do these things: 1) VCS -> Enable Version Control Integration -> Git 2) In Project view in Android Studio, select the project root folder and right click on it. Then go to Git -> Add, after that Git -> Commit Directory, and then Git -> Repository -> Push .

Whenever you get prompts in this way, just click on appropriate options.

I find the top answer little bit too complicated, although fully functional. So here is maybe little bit easier to understand practice:

Assuming you already have project, and you want to change target (Bitbucket in my case) directory.

  • Go to project directory: cd Your/project/location
  • Find your current remote: git remote (its name will be probably origin )
  • Delete it: git remote remove yourOldRemoteName
  • Make sure you deleted the remote: git remote (should display nothing)
  • Create new remote: git remote add yourNewRemoteName repositoryUrl

(If you are using Bitbucket, your url will be something like https://yourUsername@bitbucket.org/your-company/yourRepository.git and you will find it by clicking Clone button in source folder of your repository or when creating the repository.)

Hope this will be useful!

  1. Remove the git folder in Project directory

  2. Run this command git init in Terminal

  3. Vcs=> Git=>remote and add new

  4. Paste the new git URL

  5. After, verify your GitHub credentials

Now new git attached to your project

Remove and add git

//progect_path is path where .git is located
cd <progect_path> 
rm -fr .git
git init

For me, the better solucion using Android Studio with Flutter projects was:

  • Create a new project in Android Studio
  • Close Android Studio
  • Outside from Android Studio, with Finder (Mac) copy from my old (corrupted) project the entire lib folder and the pubspec.yaml file to the new one, overwriting.
  • Enable Git in the new project from Android Studio again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM