Home > Enterprise >  Delete local Git repository
Delete local Git repository

Time:01-04

I'm very new to GitHub, so please forgive the naive question. I have also had a look, I could not find this question elsewhere on stack.

What happens if you delete the original local repository?

I created a GitHub repository from an existing project. This project is now approaching completion, so for the sake of tidiness I had hoped to delete the local repository and only keep the remote repository. However, will deleting the local repository cause any issues with the remote repository? I assume the remote repository is totally independent of the local repository. However, I have no idea what is in the .git directory so I'm hesitant to delete to local repository.

Also, on this chain of thought - is it best practice to clear local repositories each time you push changes?

Thanks for your help

CodePudding user response:

Deleting your .git folder won't do anything. .git is the configuration folder for git, so if you delete it you won't be able to push any changes to GitHub. You are correct, all copies of the repository are independent of each other unless they're synced with pushes or pulls.

But there's no real point to getting rid of your .git directory, except for a deployment/release, but it's better to just have your build tool ignore the .git directory if that is the case. Removing .git will destroy any commits not synced. You'd have to re-run git init to fetch changes with remote.

What is the .git folder?

CodePudding user response:

Eeach copy of the repository is self-contained so deleting your local version will not affect the "copy" stored in GitHub, if you have pushed all your important changes to the remote repo. Your local branches and commits that were not pushed to the remote repo will not - by definition - be in the remote repo.

From the official git book Getting Started - About Version Control:

Distributed Version Control Systems

This is where Distributed Version Control Systems (DVCSs) step in. In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don’t just check out the latest snapshot of the files; rather, they fully mirror the repository, including its full history. Thus, if any server dies, and these systems were collaborating via that server, any of the client repositories can be copied back up to the server to restore it. Every clone is really a full backup of all the data.


The .git is what makes a directory a git repository, rather than being just a directory with files. .git contains the repository's history among other things.

  • Related