Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push just one file to GitHub from a local repository

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?

like image 402
kolypto Avatar asked Sep 25 '11 13:09

kolypto


1 Answers

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.

like image 175
knittl Avatar answered Sep 20 '22 00:09

knittl