remove version tracking from a project cloned from git

January 24, 2021 | No comments

Remove Git from a Repo

Sometimes we want to remove the reference to existing repository details, such as cloned from github so that we can check the code in a different git repository or a different version control system. This article covers the steps that we can take to remove git references. If we clone a repo or fork a repo from git, the newly created repository will have git references as version control. If we want to remove the git references from the new repository then we need to delete all the git references. Once we remove the git references then it will not have any reference to old repository and we can use this project folder to create a brand new repository in git or any other version control system. This article talks about how to remove
The good thing is that all the git related information is stored in a folder .git . Normally we would have only one .git folder in the root of the repository, but we might have more than one .git folder based on how the repository is configured. Apart from .git folder we might have following git specific files, .gitignore: allows to include/exclude files to be synced to git remote server
.gitkeep: allows us to include an empty directory to be synced to git remote server
. gitattributes: allows us to ensure consistent git settings across the machine.
Essentially we need to delete all these git related folder/files that will make our repository clean and without any git version details. The following sections show how to achieve the same in a Windows environment and Mac environment

Windows

The rmdir or rd command will not delete/remove any hidden files or folders within the directory you specify, so we should use the del command to be sure that all files are removed from the .git folder. Open the command prompt Navigate to the project directory, i.e. - cd path_to_your_repository
del /F /S /Q /A .git

rmdir .git

Mac

Open a terminal and navigate to the directory of your project, i.e. - cd path_to_your_repository. And run the following commands
rm -rf .git
rm -rf .gitkeep
rm -rf .gitignore
rm -rf .gitattributes
Checking if you have any .git folder left
Go to the directory of your project and run the following command which finds the only the folder with the name .git and prints its path in the console.
find . | grep -i .git

No comments :

Post a Comment

Please leave your message queries or suggetions.