Is it safe to delete a project’s .git folder?
- Usually not.
.gitis the repository itself: every commit, branch, tag and stash of the project. Your current files stay if you delete it, but the folder stops being a Git repository. - What it costs you: anything that exists only on this Mac: commits you haven’t pushed, local branches, stashes, and the whole history of a project that never had a remote. If everything is pushed, cloning again gets it all back.
- Does it come back? Only by cloning from a remote, and only what you pushed. To get space back, make the repository smaller with Git’s own tools instead.
- SiftMac’s verdict: You decide
1. What it is
When you run git init or git clone, Git creates a hidden .git folder at the top of the project. That folder is the repository. The files you edit are one checked-out version of what’s stored inside it.
objects/: every version of every file and every commit, compressed, mostly in pack files.refs/,HEADandlogs/: your branches and tags, where you are now, and the reflog of recent moves.index,configandhooks/: the staging area, the repository’s settings and remotes, and hook scripts.lfs/, in projects that use Git LFS: local copies of large files, the default place Git LFS stores them.
Deleting .git leaves your working files in place. What goes is the history, every branch and stash, and the link to the remote.
2. Where it is
<project>/.git
It sits at the top of each project and is hidden in Finder; press ⇧⌘. to show hidden files. Every repository has its own, including tools and examples you cloned once and forgot. To list the repositories under a folder with the size of each .git, changing ~/Projects to wherever you keep code:
find ~/Projects -name .git -type d -prune -exec du -sh {} + 2>/dev/null | sort -h
3. How big it gets
Git compresses history and stores each version of a file once, so .git is often smaller than you’d expect. It gets big when large files were committed at some point, because they stay in history even after you delete them from the project, when Git LFS keeps local copies of big assets, or when unreachable objects build up between clean-ups. Git’s own count, run inside the project:
git count-objects -vH
size-pack is the space taken by packed history, size by loose objects, and size-garbage by files Git considers garbage.
4. How to delete it safely
To make it smaller, keep it and tidy it. Git already runs git gc automatically when a repository has grown a lot, but you can run it yourself, for example after deleting many branches:
git gc
It compresses file revisions and removes unreachable objects older than a grace period, two weeks by default. Git’s documentation says --aggressive isn’t worth it for most repositories, and warns that --prune=now can corrupt a repository if another Git process is writing to it at the same time. In projects using Git LFS, git lfs prune --dry-run shows which old local copies it would delete; files referenced by commits you haven’t pushed are kept.
To drop the history of a project you’re done with, first make sure nothing exists only here:
git status
git stash list
git log --branches --not --remotes --oneline
The last command lists commits on local branches that no remote has. If all three come back empty, deleting the project and cloning it again later loses nothing you’ve pushed. To keep the files but drop the history, quit editors using the project and move .git to the Trash, which lets you change your mind until you empty it.
5. What happens afterwards
- Your files stay exactly as they were, but
gitcommands no longer work in that folder, and editors stop showing branches and changes. - Commits, branches and stashes that were only on this Mac are gone once the Trash is emptied.
- If the project is on GitHub or another remote,
git clonebrings back everything you pushed, in a new folder. - After
git gc, your history is unchanged; the repository just takes less space.
6. What to clear instead
If code projects are filling your Mac, the folders that rebuild are better targets: node_modules, Python environments, Rust target folders and Xcode’s DerivedData. Each comes back with one install or build. History doesn’t.
Questions
Does deleting .git delete my code?
No. The files in the project folder stay. What goes is the history behind them and the connection to the remote.
Can I get my history back after deleting .git?
Only what you pushed, by cloning the repository again. Unpushed commits, local branches and stashes can’t be recovered unless .git is still in the Trash or in a backup.
Why is .git bigger than my code?
History keeps every version of every file ever committed, including large files you later deleted. git count-objects -vH shows the packed size and git gc tidies it up. Taking large files out of history means rewriting it, which changes every commit after them.
How SiftMac handles it. SiftMac never deletes .git folders. Its space map marks them as Git history, yours to keep, and its Developer files category only reads .git to tell when you last worked on a project, so it can list that project’s rebuildable folders, like node_modules, once you haven’t touched it for months.
Download SiftMac · scanning is free, and so is your first 2 GB of cleaning · See how it works