10

I'm new to git and I think I accidentally cloned in the root directory. When I committed one file (index.html) I noticed my whole computer (my desktop, my documents, etc) all in untracked files. I deleted the repository and I want to remove all the untracked files, obviously without deleting everything from my computer. I am new and paranoid about losing my files.

NICK
  • 139
  • 1
  • 2
  • 10
  • Do you have a `/.git` directory? (If so, what are you doing running as root, and doing anything in `/`? That's dangerous, especially when you're a newbie. I wouldn't do it — and I've been working with Unix for long enough that's it's quite possible I've been using Unix longer than you've been alive.) If you have a `/.git` directory, was there anything of value in it before you started these operations? If you don't, where is the `.git` directory? – Jonathan Leffler Dec 27 '15 at 21:07
  • The files being untracked isn't a major problem (Git won't do anything with untracked files), but the location of your Git repository probably is. – Jonathan Leffler Dec 27 '15 at 21:24
  • Yes i do have /.git I can't cd into it. What should I do? Im freakin out right now – NICK Dec 27 '15 at 22:06
  • Remember what it says on the cover of The Hitchhiker's Guide to the Galaxy: **Don't Panic**. You've not yet done anything that can't be undone harmlessly – Jonathan Leffler Dec 27 '15 at 22:29
  • It appears you're on Mac OS X. It also appears that you have created a `.git` directory underneath your `$HOME` directory — `/Users/nick/.git`. You said that you cloned something — was that an external Git repository, or another Git repository on your machine? What would be the consequences to you of doing `mv $HOME/.git $HOME/mistaken.git.directory`? Would you get back to where you expected to be w.r.t `git status`? Did you make any important changes to the material in the repository? The `mv` command I gave is safe because it can be undone. – Jonathan Leffler Dec 27 '15 at 23:56
  • When you're sure you don't need it, you can use `rm -fr $HOME/mistaken.git.directory` to remove it, and start over. When you next clone a project, make sure you do so in a suitable sub-directory of your $HOME directory. You said somewhere you think you have a `/.git` directory that you can't `cd` into. That probably means that someone with root privileges created that repository. If it wasn't you and it's your machine, think about removing that, but you need to know who it belongs to and why they were playing in the root directory. The person must have had root privileges when it was created. – Jonathan Leffler Dec 28 '15 at 00:00

3 Answers3

31

You must have run

git init

somewhere. You need to find the folder you ran this in. Just run:

git status

somewhere you think is now under git "control" and you'll see by the paths: say if you have a path like Desktop/myFolder => you know the folder that contains desktop is you git root folder. Just navigate there and run :

rm -r .git

And all should be back to normal :)

Now that we got the status output :) .. Alright as you can see the root of this thing is you home folder. So just do this:

  1. move to the home folder

    cd ~
    
  2. delete the git repo

    rm -rf .git
    

    => git repo is gone for sure :)

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Armin Braun
  • 3,645
  • 1
  • 17
  • 33
  • I did run git init but I do not remember where. I think it was the first thing I ran when the terminal opened. Im confused regarding the paths and "control". Can I message you ? Thnks – NICK Dec 27 '15 at 21:17
  • Just add the output of `git status` in some directory to the question maybe? That way the next guy running into this will be helped also ;) – Armin Braun Dec 27 '15 at 21:19
  • 1
    @NICK: In your terminal, first run `ls -ld /.git`; if that shows you a directory, that's where you're repository is. If that doesn't show anything (generates an error message), run `find $HOME -type d -name .git` to find Git repositories. If that doesn't show up anything either, change `$HOME` to `/`, but be aware it will read through all the directories in the system (that you have permission to access). Then you've found your Git repository. You can add that info to the question, and get advice from there. – Jonathan Leffler Dec 27 '15 at 21:21
  • In that case deleting the repo from github.com is sort of irrelevant to your local problem. Appears your git repo on the local machine is gone already. Probably delete it on github.com anyhow though, does not seem as though it contains what you wanted it to contain in the first place :) – Armin Braun Dec 27 '15 at 21:29
  • No the untracked simply states what files in the folder you initialized the git repository in, are not (yet) tracked by git. This has nothing to do with what's been pushed to github.com for example. It is safe to say though, that if you deleted the github reposity those files are likely nowhere but on your machine :) This is not a matter of taking time though, git instantly realizes this once the .git folder is gone. Maybe just nervous/bad timing with the git status and prior deleting of the repo ? – Armin Braun Dec 27 '15 at 21:37
  • @JonathanLeffler I think I found the location but it says no file or directory. What should I do? – NICK Dec 27 '15 at 22:05
  • It says that for the `rm -r .git` ? If so, then you're not at the root of your repo – Armin Braun Dec 27 '15 at 22:06
  • @ArminBraun, thank you for your patience but I don't understand how to get there. Could you please explain? Thank you – NICK Dec 27 '15 at 22:16
  • Np, but look :) Make your life easier here, so I can give you clear steps: just `cd` to whatever folder you think is still under git and run `git status` :) Then paste the output here or better yet add it to your question and you'll get a step by step guide to resolving your issue in minutes ;) – Armin Braun Dec 27 '15 at 22:23
  • @ArminBraun I pasted it. Let me know what you thinK! Thank you!! – NICK Dec 27 '15 at 23:11
1

Just Goto C/D or any other drives & run git command 'rm -rf .git'.

Shabbir Essaji
  • 584
  • 1
  • 10
  • 17
0

Anyone having these issue looks like you've created a repo for your entire disk. You can use this command to locate the .git folder in the topmost level of disk.

git rev-parse --show-toplevel

The git rev-parse --show-toplevel command is used to display the top-level directory of the current Git repository. When executed within a Git repository, this command will output the absolute path of the top-level directory of that repository.

This command will output the path of .git folder, go there and use

rm -rf .git

This command will delete the .git folder. Everything will be fine now.