wondering
wondering

Reputation: 373

How to remove git related data from a git clone?

I want to clone a specific branch of a git repository and copy it to my own private git repository. The original repository is very huge and has a lot of branches, which I don't need at all. I also don't need any file history. Forking is not an option, because forked repositories are not allowed to be private on github.

After running

git clone https://example.com/repo.git -b my-branch

how can I get rid of all git-specific information in the local copy, keep only my-branch, as if I just created the contained files?

Upvotes: 1

Views: 6437

Answers (1)

Justin Howard
Justin Howard

Reputation: 5643

You can simply delete the .git directory and re-initialize the repository.

rm -rf .git # Delete all git information
git init # Recreate an empty repo
git add --all # Re-add all the files to the index
git commit -m 'Initial fork from example.com/repo.git'

Upvotes: 7

Related Questions