
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tlug] Git: bring in a file from another branch
Darren Cook writes:
> I've these three branches:
> master: git clone of a github repository. (Note, an open source
> *library*, not an application.)
>
> custom: a branch of master, with my bug fixes and new features that
> are fed back to the main project.
>
> myapp: a branch of custom, adding application code that uses this
> library.
Don't do that last. It hurts. I recommend you try this instead:
# make a repository for MyApp
cd /usr/local/src
mkdir MyApp
git init
# pull in the library as a submodule
git submodule add github:open-source-library # upstream URL
git submodule init
git submodule update
# make a branch for local work
pushd open-source-library
git checkout -b custom
popd
# Tell the submodule mechanism that you really do want to commit to it
# *and* have it communicate with upstream.
# The merge itself is a no-op here. In your real application where
# you already have code and changes staged, YMMV.
git submodule update --rebase
Now you can add the MyApp code, and git will not get confused about
which is which. To push your changes to the library to upstream, you
just cd to that directory, merge custom into master, and git push.
However, looking at the few submodules I actually use, I realize I've
never tried to push to upstream from this setup. So it may be more
complicated than I think.
The main thing you need to be careful about is that the *parent*
project (MyApp) remembers the commit that you originally grabbed with
"git submodule init; git submodule update". If you clone from MyApp,
you won't get the local changes at all (unless they've been pushed
upstream and you've updated .gitmodules to reflect that).
> Also, is it possible to veto a directory from being checked out in a
> certain branch?
Not really. If your workflow is adapted to the situation, you can
merge from myapp into custom, then just rm -rf those directories,
commit, and learn to just never ever work on "lib" and "examples" in
the "myapp" branch. But if you ever commit a change to one of those
files in myapp and try to merge back to custom or master, you'll get a
modify/delete conflict which is a mild PITA. I know plenty of smart
people who regularly find themselves working in the wrong branch,
though, and for them one solution is submodules.
Home |
Main Index |
Thread Index