hubbabubba
hubbabubba

Reputation: 997

How do I completely remove Git from an Android Studio project?

I'm developing my first project with Android Studio and can't quite get Git and GitHub configured properly. I'd like to completely remove my project from Git/Git from my project and start fresh. How can I do this? Also, there is no .git folder in my project folder, so where are my git files stored locally and how can I completely start over with Git and GitHub?

I've set VCS to 'None' in Settings -> Version Control, but I don't think this removes Git. The directory shows as "Unregistered roots". I was also wondering if it is normal to have several directories showing in this view? At times I've had and some directory, and at the moment I have my project directory and as Unregistered root "app ( [my app directory] )"...

At one point I managed to push stuff onto GitHub, but only some of my project files. Others, which I added to the project after the initial commit, showed up as unversioned, I added them and tried to commit and push, but couldn't. Also, they went back to unversioned every time I built my project. This is why I'd like to completely start over

Upvotes: 56

Views: 85260

Answers (7)

Daljit Singh
Daljit Singh

Reputation: 533

for Android Studio Giraffe | 2022.3.1 version, you should go to: File->Settings->Version Control->Directory Mappings->"-"(Minus Sign in Top Left corner)->Apply->Ok enter image description here

Upvotes: 2

basileus
basileus

Reputation: 445

What I have done to remove Android Studio project binding to GitHub is:

  1. I removed project on https://github.com first (you do not have to remove your project from GitHub though. Treat it as optional step)
  2. To remove GitHub binding to Android Studio project you need to go in Android Studio to File -> Settings -> Version Control. But DO NOT expand it, just mark it. Then, on the right hand side change, Git to None (red arrow on the picture below indicate this) enter image description here
  3. Finally remove hidden directory .git from your Project directory, this one which is specified in the picture below (I actually blurred mine :-) ).

Follwoing this three steps I were able to completely re-create fresh project on Github with the same Android Project.

What I do not like in the first answer (and I am not allowed to send comments yet) is that actually removes Github account, but do not remove binding between project in Android Studio and Github.

EDIT In newer version of Android Studio (i.e. Flamingo), in bullet (2) you need to go to: Settings -> Version Control -> Directory Mappings

Upvotes: 17

WernerVA
WernerVA

Reputation: 1091

Just an updated screenshot of the location of said '-' button in Android Studio 2022.1.1 on Windows.enter image description here

Upvotes: 8

Lins Louis
Lins Louis

Reputation: 2643

From Android Studio Preferences,(My Android Studio version 3.6.1) Select Version Control->Select git Path-> Click ' - ' (minus button)->OK

Windows: File > Settings > Version Control > Select Project > '-' (Minus Button) >Apply > Ok

UPDATE:

Currently google updated this settings.So if you want to delete GitHub connection from your project Open android Studio Settings ->Version Control ->Github -> click ' - ' (minus button) -> Apply -> OK

enter image description here

Upvotes: 90

Muhammad Ullah
Muhammad Ullah

Reputation: 332

You should remove all the files in '.git' folder for that, Go to this path: "D:\file\YourProjectName\android" and in search bar search for '.git' and delete all the files there.

Upvotes: 0

Zoe - Save the data dump
Zoe - Save the data dump

Reputation: 28228

AFAIK, you can't remove it using Android Studio (there isn't a button for removing Git from a project). (Upd.: now incorrect, but the rest of this answer is still correct and functional, because Git still works the way this answer relies on).

In addition, .git is a hidden folder, meaning it's, well, hidden. ls needs -a to show it, and most file explorers don't show the folder.

Git is also not dependent on Android Studio in any way. All of the Git history is stored in the .git folder, and is usable with or without Android Studio.


There are (at least) three options.

The first method to removing it is fairly simple. So when you go into your project root, simply append /.git to the path.

So if your project root is D:/files/SomeProject, append the Git folder so the actual path becomes D:/files/SomeProject/.git and delete all the files and folders in there.

Alternatively, you can also use command prompt to delete it (note that this assumes you cd into the root dir first):

Windows:

rd /s /q ".git"

Linux/Mac:

rm -rf .git

And there's of course the option to show hidden folders, but this shows them everywhere. At least for Windows (10), search for folder (alternatively in an applicable language if your computer doesn't use English) and select "Show hidden files and folders". Scroll down until you find Hidden files and folders and select show. Other operating systems have different ways, most of which are likely covered somewhere on the internet (possibly a different Stack Exchange as well).


No matter which way you do it, now you just do git init and you've restarted it. All previous history will be gone, and the active tree will be the one left, so make sure you're on the right branch. When you delete the .git folder, there's no way to recover the history without re-pulling from a remote, and this assumes you have/use one.

Note that if your project is already uploaded to GitHub, you have to use the force flag (-f) for the push. Otherwise it'll just reject the push. Use the -f flag extremely carefully; it will cause problems for anyone else working on the repo (though this is only really a concern if there are others), and it will overwrite the current version of the repo stored on GitHub, or in any other remote you push to, and this is usually unrecoverable.

Upvotes: 48

tn-nguyen
tn-nguyen

Reputation: 137

just remove hidden folder ".git" from your project folder

Upvotes: 4

Related Questions