Ever wanted to fork a subdirectory and not the whole Git/GitHub repository. Well I have, I recently had to fork a subdirectory of one of the repositories I wanted to work on without the need to fork the whole repository. In this post, I will show you how it's done.
Note: I do not think you can fork subdirectories through GitHub's web interface
git clone https://github.com/<someones-username>/<some-repo-you-want-to-fork> cd some-repo-you-want-to-fork
git subtree split --prefix=./src -b dir-you-want-to-fork git checkout dir-you-want-to-fork
Head over to GitHub and create a new repository you wish to fork the directory to.
cd some-repo-you-want-to-fork git remote set-url origin https://github.com/<username>/<new_repo>.git
git fetch origin -pa git push -u origin dir-you-want-to-fork
git clone https://github.com/<username>/<new_repo>.git cd new_repo git checkout --detach git fetch origin '+refs/heads/*:refs/heads/*' git checkout dir-you-want-to-fork
You now have a "fork" of the
If you ever run
git merge master and get the error fatal: refusing to merge unrelated histories; run
git checkout dir-you-want-to-fork git merge --allow-unrelated-histories master # Fix conflicts and git commit -a git push origin dir-you-want-to-fork