MacOS: clear all untrack files from git history

Issue

Long time ago, I’ve worked a little with git on a project that I started, and left. Now I am starting a new project, and I would like to use git for version control.

When I checked to be sure if git is available or uninstalled previously, I can see that it’s available:

% git --version
git version 2.31.1

% which git
/usr/local/bin/git

But then, it appears git was tracking some files that I no longer need, and would clear everything altogether.

~ % git status
warning: could not open directory '.Trash/': Operation not permitted
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
    .CFUserTextEncoding
    .DS_Store
    .RapidMiner/
    .Rhistory
    .Xauthority
    .anaconda/
    .android/
    .anydesk/
    .atom/
    .bash_history
    .bash_profile
    .bash_profile-anaconda3.bak
    .bash_profile.backup
    .bash_profile.pysave
    .bash_sessions/
    .....

These are files I no longer needed tracked (don’t even remember which project they belonged to).

So I want to clear this history, have a clean git for a new project I will start working on.

So I have done all of the following commands:

git git reset --hard
git clean -f
git clean -fx

However, I still see this as untracked when I do:

~ % git status
warning: could not open directory '.Trash/': Operation not permitted
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
    .CFUserTextEncoding
    .DS_Store
    .RapidMiner/
    .Rhistory
    .Xauthority
    .anaconda/
    .android/
    .anydesk/
    .atom/
    .bash_history
    .bash_profile
    .bash_profile-anaconda3.bak
    .bash_profile.backup
    .bash_profile.pysave
    .bash_sessions/
    .....

How do I get rid of these, to start a clean git versioning?

Solution

First of all, those files that are listed as "untracked" are, like it sounds, not tracked by Git. They are listed because they are inside of a Git repo folder and not currently ignored. This issue will go away in a moment anyway…

It looks like you created a Git repository in your home directory (~). There is likely a .git folder in that directory. If you don’t need that anymore you can delete it. (Consider backing it up first though just in case.) Then consider creating a new folder where you will store all of your Git repos. Maybe a folder called Git or Code or Repos, etc. Then inside of that folder, create a folder for each project you wish to work on, e.g. Project1. Then navigate into that folder and type:

git init

to initialize a new Git repo in that folder. You can (and usually should) have separate Git repos for each independent project you are working on.

Answered By – TTT

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published