0

Apparently I did git init before starting on my current git repository, im unsure on how to remove all the untracked files without deleting it permanetly from my computer or deleting my current repository on github.I suspect that /c/Users/A/.git is the issue, because basically most files on my computer is listed as untracked:

A@LAPTOP ~ (main)
$ find $HOME -type d -name .git
/c/Users/A/.git   #I WANT TO DELETE THIS
find: ‘/c/Users/A/AppData/Local/Temp/msdtadmin’: Permission denied
/c/Users/A/Desktop/Test/Project/GIT/.git # I DO NOT WANT TO DELETE THIS

How do I resolve this issue?

Andycode
  • 171
  • 1
  • 1
  • 10

1 Answers1

1

It looks like you have .git folder in the wrong place. You can rename it to anything not .git – it won't have any effect on other files. If you still need it, you can rename it back:

mv .git _.git_backup

If you made a mistake, the operation is reversible:

mv _.git_backup .git

If you have the .git directory in the wrong location and already worked on it, it is best to move it somewhere else to prevent any accidents (switching branches, losing worktree changes, etc.).

Create a new empty folder somewhere on your computer, e.g. /tmp/recovery and copy your .git folder there. Then switch to the directory and perform a git status. Does its output match your expectations? It probably will tell you about lots of "deleted in the worktree" files. If that's the case, do git checkout HEAD -- . in your new empty directory.

This will restore the files that are tracked in the Git repository. Check again your directory to match your expectations. Maybe you can manage to go from there. If not, let us know which files are available in the new directory and what you expect instead (edit your question and add this information to it).

In the end, rename the original .git directory in your home folder (rename, not remove. renaming allows you to undo the operation).

knittl
  • 246,190
  • 53
  • 318
  • 364
  • Does this command rename the first .git folder and not the second? – Andycode Dec 05 '20 at 19:15
  • It renames the `.git` folder in your current working directory. If you `cd` into `/c/Users/A` it will rename that folder. If you `cd` into your `…/Desktop/Test/Project/GIT` folder, it will rename that one. – knittl Dec 05 '20 at 19:17
  • It won't let me cd to that path apparently. It gives me error: bash: cd : too many arguments. What is the correct syntax? (Im new to gitbash) – Andycode Dec 05 '20 at 19:19
  • It should work. Does your path contain whitespace by any chance? If so, you have to quote it: `cd '/c/Users/My User Name'` – knittl Dec 05 '20 at 19:30
  • Sorry for the late answer. I can't seem to get this to work for some reason. – Andycode Dec 09 '20 at 18:10
  • @Andycode "not working" or "can't get it to work" are very bad problem descriptions. What command are you running what error do you get (if any)? I/we cannot see your screen and don't know what you see. – knittl Dec 09 '20 at 18:39
  • Apparently I do not want to delete the first .git as mentioned, since the R script im working on is in a folder that builds on that .git repository. The last .git mentioned in my question is from earlier work and not related to what im doing. So the issue is that i did a git init for everything within 'c/Users/A'... i just want to remove the untracked files so that i can git add. only the changes im doing. So how do I remove untracked files without permanently deleting them from my computer? – Andycode Dec 09 '20 at 18:45
  • I found this (https://stackoverflow.com/questions/34484800/entire-computer-in-git-status-untracked-files ) that addresses the issue, but the problem is that someone have already made changes in another branch in the git repository. Will this solution delete everything done on another branch as well? – Andycode Dec 09 '20 at 19:11
  • @Andycode I have updated my answer. Can you recheck if that helps? – knittl Dec 09 '20 at 19:38