X
Popular Searches

How to Remove Git Version Tracking from a Folder

If you’ve download a .zip from Github, or cloned a repository, it will be linked by default to the source repository. If you want to switch to your own repository, or remove version tracking entirely, you can do that easily.

Removing Git Entirely

Git stores all of its data, and most of its configuration, in a folder named .git. Removing this folder will completely remove Git version tracking from the directory, but it will also remove all Git version history. The folder will be like it never had Git installed.

If this is what you want, you can delete it. But, you may want to instead switch to your own repository, and keep the version history of the folder. This is useful if you want to download and fork a Github project (though Github does have tools to do that automatically).

The .git folder is hidden though, so the easiest way to delete it is through your terminal. If you’re connecting to a server over SSH, you’ll have to do this anyway. Navigate to the folder, and remove the .git folder:

cd ~/Downloads/your-git-repo
rm -rf .git

If you’d prefer to delete it through your file browser, you’ll need to enable hidden files. You can do this on Windows by pressing Windows key and searching for “Show Hidden Files.”

Advertisement

Apple doesn’t make it as easy for MacOS. You’ll still need to use the terminal, and modify some config for Finder:

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

After that, you’ll be able to delete the .git folder from your file browser.

Switching To a New Repository (Remote)

If you’d like to keep the version history of your folder, you’ll want to leave the .git folder alone and instead remove and replace the existing remote. Git uses “remotes” to configure where it pulls updates from.

Note that removing a remote does not effect your repository—it simply disconnects it from Github, or wherever it’s hosted. You can then add a new remote, pointing to a new Github repository, and push your .git folder to your own repo.

You can list all the remotes alongside the URL they’re pointing to with remote -v:

git remote -v

You probably want to remove “origin,” the default remote. You can do that with remote -rm:

git remote rm origin

Then, you’ll want to fetch the new remote:

git fetch origin

And push the whole folder:

git push -u origin master
Advertisement

If you made changes though, you will need to add and commit those changes before pushing.

Anthony Heddings Anthony Heddings
Anthony Heddings is the resident cloud engineer for LifeSavvy Media, a technical writer, programmer, and an expert at Amazon's AWS platform. He's written hundreds of articles for How-To Geek and CloudSavvy IT that have been read millions of times. Read Full Bio »

The above article may contain affiliate links, which help support CloudSavvy IT.