Reputation: 2440
I develop some scripts for handling my bibtex-databases and PDFs.
For convenience, I manage both the database and the scripts in the same git repository (a thing I do not want to change). However, I would like to make my scripts available (e.g. on github) but not my database or pdfs. Still, I want to have the same commit-history both on github and locally for the scripts.
I thought about having a github-branch and to push only this branch. But how would I update the branch with the commits done to the scripts in the master branch?
Are there any other ways to do this?
Upvotes: 18
Views: 8927
Reputation: 2440
I followed the advice given by @larsmans and it turned out to be very convenient. Here are some more details for the procedure:
## getting the scripts into a separate branch for github
# create a root branch 'scripts'
git symbolic-ref HEAD refs/heads/scripts
rm .git/index
git clean -fdx # WARNING: all non-commited files, checked in or not, are lost!
git checkout master script1.py script2.py
git commit -a -m "got the original scripts"
git checkout master
git merge scripts
# push the scripts branch to github
$ git remote add github [email protected]:username/repo.git
$ git push github scripts
Now I can develop in the scripts-branch and merge with the master branch whenever I need it for my database.
One caveat: The first merge after adding a new file that is in both branches will result in a conflict (because the scripts-branch is a root-branch). So it's best to get the scripts from the master branch and commit them immediately.
Upvotes: 3
Reputation: 467261
You could use git subtree
to split off the scripts directory into their own branch (with complete history for that subdirectory) which you can then push to GitHub. You can run git subtree again to keep the split repository up to date.
To give an example, once you've installed git subtree
you can do:
git subtree split --prefix script-directory --branch just-scripts
git push github-scripts just-scripts:master
... assuming that your scripts are in script-directory
, and github-scripts
is a remote that points to the URL of your GitHub repository intended for just the scripts.
Upvotes: 12
Reputation: 363597
But how would I update the branch with the commits done to the scripts in the master branch?
Cherry-pick the commits pertaining to the scripts from master
into the public branch. Or, edit the scripts in their own branch, then merge the changes into master
when you need them.
Upvotes: 3