1

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?

1 Answer 1

7

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'
Sign up to request clarification or add additional context in comments.

1 Comment

My specific issue was apparently a second .git directory in a sub-directory. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.