Reputation: 716
I have code that I push to my Bitbucket account regularly. Now, I want to push to two different remotes with single commit, but with different git.config files. I know that I can setup different remotes like this:
git remote set-url --add --push origin git://original/repo.git
git remote set-url --add --push origin git://another/repo.git
The idea is that one config file I will be setup to include all of my code and another to not include it all. Let say code in folder "A" will be pushed to just one of the remotes. Then I will be able to give an access to the "incomplete" code to someone.
I know that git.config is specific to project, user and system and I am wondering is it possible to setup workflow like this. Is there any way to acompplish that?
Upvotes: 2
Views: 478
Reputation: 1429
Git branches (local as well as remote ones) do not work on directories and files but on commits.
Lets name the full source repository orig
and the stripped repository pub
. As the history of pub
isn't allowed to contain changes unique to orig
the repositories can not simply share the same commit history. Also two bramches (orig
forking pub
and adding some stuff e.g.) could be possible but I can't think of any convenient or even usable workflow right now.
It should be possible though to write a small script which utilizes git filter-branch
to create the pub
tree from the orig
repository and push it to the pub
remote.
As I don't know the exact commands right now from scratch, consider this as a big comment giving a general direction for a possible solution ;)
I'll add some more concrete ideas when I got the commands right.
Edit 0: at git-scm is an example to extract a subdirectory:
git filter-branch --subdirectory-filter foodir --tag-name-filter cat -- --all
The --tag-name-filter cat
is used to preserve tags.
You could use this command to either write a script, that clones orig
, applies the filter and pushes to the pub
remote everytime you want to.
You could also issue this command once to split up your project into several repositories as SébastienDawans stated.
Upvotes: 1