Skip to content

@bertjwregeer /

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Procedure to take a library that contains files for multiple programming languages, and split off the language specific features into separate branches
cat << EOF > /dev/null
These procedures are helpful if you have a structure like this in your source tree and it can be anything like
Google protobuf, grammar syntax, shared source code of some sort that gets transformed to Python and C++, or
really anything that has a common base from which it is derived but when included (subtree'd/submoduled in git)
we only need the language specific part, not the rest.
What we do is create completely new branches in which we place a copy from the proper subdirectory from the
master branch. Yes that technically means we are duplicating files/commits in two different locations, but it
is a better option that having your Python specific source tree carrying around C++ files it does not need.
master -\
|- cpp
\ - file1.cpp
|- python
\ -
|- src
lang/python -\
| -
lang/cpp -\
| - file1.cpp
Then when you use to transform your src to either cpp or python, you can use the following steps
to update the branches.
# +++
git clone ... # If you don't already have a copy of the mainline sitting around
# or
git checkout master
git fetch origin
git pull origin
# +++
# +++
# Create the branches for the first time
git branch lang/python master
git branch lang/cpp master
git checkout lang/python
git filter-branch -f --subdirectory-filter python HEAD
# Push the local branch to origin and set it to track the remote
# in the next update you can then use git push instead...
git push -u origin lang/python
git checkout lang/cpp
git filter-branch -f --subdirectory-flter cpp HEAD
git push -u origin lang/cpp
# +++
# or update the branches you currently have
# Create local branches that track the remote branches
git branch lang/python origin/lang/python
git branch lang/cpp origin/lang/cpp
# Checkout the entire source code from master so we can transform it...
git checkout -b lang/python-update master
git filter-branch -f --subdirectory-filter python HEAD
git checkout lang/python
git merge lang/python-update
# Move back to the master
git checkout master
# Checkout the entire source code from master so we can transform it...
git checkout -b lang/cpp-update master
git filter-branch -f --subdirectory-filter cpp HEAD
git checkout lang/cpp
git merge lang/cpp-update
# Move back to master
git checkout master
# This will push lang/python, lang/cpp because we set them up to track the remote when we branched them...
git push
# Delete the old branches, uses uppercase D because otherwise it will complain about not fully merged
# (mainly because you are on master, and master off course has no record of these branches since they are stand-alone)
git branch -D lang/python-update
git branch -D lang/cpp-update
# +++
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.