I have a repo with multiple scripts. One of them is especially useful and I want to share it using GitHub.
How can I export one file (with commit history) to a GitHub repo without sharing all other scripts from the same repo?
Something like:
git remote add 'origin' [email protected]:user/Project.git
git push -u 'origin' ./useful-script.sh
But how do I specify a single filename? Or should I create some kind of special 'partial' commit?
You'd have to use filter-branch
to rewrite your history and strip everything but that single file:
git filter-branch --index-filter '
git rm --cached -f -r .;
git add ./useful-script.sh;
' --all
should do the job.
If --index-filter
does not work (I'm not sure about that git add
there), try `--tree-filter' with the same argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With