Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push only part of a repository

Tags:

git

github

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?

like image 591
thias Avatar asked Oct 21 '11 13:10

thias


People also ask

Does git push only push changes?

By default, git push only updates the corresponding branch on the remote. So, if you are checked out to the main branch when you execute git push , then only the main branch will be updated. It's always a good idea to use git status to see what branch you are on before pushing to the remote.


2 Answers

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.

like image 104
Mark Longair Avatar answered Sep 18 '22 13:09

Mark Longair


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.

like image 25
Fred Foo Avatar answered Sep 18 '22 13:09

Fred Foo