Git - too many untracked files; should i remove working tree?

hi i see that the sidebar has 5k+ files that are untracked which are irrelevant.

Is this because the working tree is pointing to the main user directory? if so, what can i do to remove this?

Yaz@DESKTOP-AJUT MW32 ~ (master)
$ git worktree list
C:/Users/Yaz  0000000 [master]

This? git worktree remove [-f] or this? git worktree move
Or any other recommendations would be appreciated :slight_smile: new to github

Seems that you opened vscode on the user directory, and one way to fix that is opening only your project folder. On the top menu you can try clicking on “File” -> “Open Folder…” and select your project folder.

hi i attempted this but it did not work. the moment i open vs code, it will show the large number of files

‘The git repository at ‘c:\Users\Yaz’ has too many active changes, only a subset of Git features will be enabled. Would you like to add ‘node_modules’ to .gitignore?’

Do what it says and add node_modules to the .gitignore file

Sorry, it’s not clear what your problem is. Is it one of these:

  • Do you like to have your main user directory as the root of your project?
    • I don’t recommend this, user’s directory will inevitable contain a lot of files and marking each of them as ignored will be hard.
  • Do you want to remove the git from your main user directory?
    • For this you can just search for a .git folder in the user directory and manually remove it.

Hi sorry for the late reply:

  1. yes, i dont want my main user directory to be the root. how can i change this? i accidentally created a git folder in my main directory

  2. if i just remove the git from the main user directory, will that do it? or is that wrong?
    (if i remove the git from the main directory, what will be the new master?)

Yes, just delete the .git folder, it’s not supposed to be there so get rid of it (at the minute you are trying to make git track every file in your root directory). Then reinitialise in the correct directory (and make sure you add node_modules to the .gitignore file).

If you delete it, you won’t have anything tracked, nothing will be “master”, this is what you want at the minute. The . git folder is just where the record of what’s being tracked lives, and atm it isn’t tracking anything you want, so deleting it is fine. If you initialise a git repo in the wrong folder, always just delete the .git folder and start again in the correct place

1 Like

thats great - yes i deleted it and now the large number of untracked files has disappeared.

And so, i dont need to have anything for a master file. Currently, i “git init” in the folder i want, then git add . , then git commit, then push the repo without assigning any folder as a master.

noted for gitignore in regards to node_modules.

Yes, but if you’ve already started making changes and commits, won’t you lose that history?
For one project I accidentally initialized the git repo one directory too high and started making commits without realizing. It was the only thing in that top directory (/my-project/my-REAL-project) so it wasn’t really a problem. But it was annoying.

I discovered that you can actually move the .git folder and not lose any of your history. The first commit you make will be a big one of all the “renamed” files.

mv .git my-REAL-project 
cd my-REAL-project
git add .
git commit

The “master” is the main/default branch of your project. It’s created when you initialized git with git init. It just means that those versions of the files are the default branch of your project. If you want to make major or experimental changes, you can create a new branch. After those changes are complete you can merge that branch back into master. Branching is kind of the point of git, so it’s good to learn eventually.

Yes, in certain circumstances you may want to do this, but ideally you don’t, you just delete. The issue is is that if you have committed changes, theres a very high likelihood that the git history is polluted by dint of making commits in a completely different directory. ie if it’s the root, then anything personal you do on your computer has the potential to be marked as a change, and it’s then ridiculously easy to accidentally commit completely unrelated stuff (often vast amounts of unrelated stuff if you’re not paying attention). And if that is the case, it often becomes very difficult to cherry pick out those erroneous commits.

As it is, yes, it may be fine, but that’s context sensitive, and nuking the entire thing is generally far, far easier and the correct thing to do.

1 Like