I have a django project managed with git. I am git pushing it to my host. Now, I want to be able to push just one of the directories (inc. all sub dirs) to another git repo. How is it possible, if it is possible at all?
Edit: So I want that directory to be a git repo itself.
You could look at git’s support for submodules. You would add the second repository as a submodule to your main project, e.g. with commands like:
When you change into the
library-codesubdirectory, it’s as if the parent repository doesn’t exist – you can changeoriginto use a transport that you can push over and then push as if it were completely independent.To specify that you want the submodule to be at a particular version, you should change into the submodule and use
git checkoutto switch to the right version. Then you change back up to the main repository and stage and commit that new submodule version with:The tree of the main repository just stores the version that the submodule should be at, so when you push the main repository, it’s not pushing any of the files in the submodule.
In order to split off this subdirectory, while preserving history, you’ll need to clone your original repository and user
git filter-branchto rewrite the history, as described in this answer:Then you can push that to a newly created repository GitHub repository, return to your original project, remove the subdirectory, and replace it with the submodule as described above.
If you’re not very familiar with git concepts then this may be difficult for you – I would recommend reading up on git submodules beforehand.