While trying to figure out a good workflow with git subtree, I would like to track the upstream branch (generally different than master
) that has been used when adding a git sub-tree.
More specifically, assuming your defined the following remotes and used to fetch them:
$> git remote add -f easybuild-easyblocks https://github.com/ULHPC/easybuild-easyblocks.git
$> git remote add -f easybuild-easyconfigs https://github.com/ULHPC/easybuild-easyconfigs.git
$> git fetch easybuild-easyblocks
$> git fetch easybuild-easyconfigs
You can see the different remote branch:
$> git show-ref | grep -v tags | grep easybuild
f4b4752bcadd5dd44aa74ee03f4bd19b75810bdb refs/remotes/easybuild-easyblocks/develop
49a1e893160c6c1d2ad50109265e55586c377c1e refs/remotes/easybuild-easyblocks/master
173aa5cabddf998e2ad672135752a33875095f8b refs/remotes/easybuild-easyblocks/v1.8.x
49a1e893160c6c1d2ad50109265e55586c377c1e refs/remotes/easybuild-easyblocks/v1.9.x
770c5246667d7741c02d4e1f4d4a50fb8cd3fcbe refs/remotes/easybuild-easyconfigs/develop
d8422c6f7aace405f1089f178edabb9316629d4b refs/remotes/easybuild-easyconfigs/master
5f3be9e2d5cbb2844ebf74ede15e2c30a8b12705 refs/remotes/easybuild-easyconfigs/uni.lu
0382ff527360f1baa192bb92597552cc379bba68 refs/remotes/easybuild-easyconfigs/v1.8.0.x
d8422c6f7aace405f1089f178edabb9316629d4b refs/remotes/easybuild-easyconfigs/v1.9.x
Now assumes that you define two new git subtree to track the upstream branch develop
for the remote easybuild-easyblocks
(respectively v1.8.0.x
for the remote easybuild-easyconfigs
):
$> git subtree add --prefix easybuild/easyblocks --squash easybuild-easyblocks/develop
$> git subtree add --prefix easybuild/easyconfigs --squash easybuild-easyconfigs/v1.8.0.x
You end with a clean directory layout where easybuild/*
hold in separate directories the latest version of the corresponding repository.
I can now check the head commit hash of all branch by running:
$> git branch -v -r --abbrev=40
easybuild-easyblocks/develop f4b4752bcadd5dd44aa74ee03f4bd19b75810bdb Merge pull request #314 from boegel/version_bump
easybuild-easyblocks/master 49a1e893160c6c1d2ad50109265e55586c377c1e Merge pull request #312 from hpcugent/develop
easybuild-easyblocks/v1.8.x 173aa5cabddf998e2ad672135752a33875095f8b Merge pull request #281 from boegel/1.8.2_release_notes
easybuild-easyblocks/v1.9.x 49a1e893160c6c1d2ad50109265e55586c377c1e Merge pull request #312 from hpcugent/develop
easybuild-easyconfigs/develop 770c5246667d7741c02d4e1f4d4a50fb8cd3fcbe Merge pull request #500 from fgeorgatos/contrib_qtop
easybuild-easyconfigs/master d8422c6f7aace405f1089f178edabb9316629d4b Merge pull request #544 from hpcugent/develop
easybuild-easyconfigs/uni.lu 5f3be9e2d5cbb2844ebf74ede15e2c30a8b12705 add Allinea-4.2-34164-Ubuntu-10.04-x86_64.eb
easybuild-easyconfigs/v1.8.0.x 0382ff527360f1baa192bb92597552cc379bba68 Merge pull request #473 from boegel/v1.8.0.x
easybuild-easyconfigs/v1.9.x d8422c6f7aace405f1089f178edabb9316629d4b Merge pull request #544 from hpcugent/develop
Now I wish to pull the latest changes from the subtrees. Thus I run:
$>git fetch easybuild-easyblocks # fetch latest changes of the remote before merging
$> git subtree pull --prefix easybuild/easyblocks easybuild-easyblocks develop --squash
$> git fetch easybuild-easyconfigs
$> git subtree pull --prefix easybuild/easyconfigs easybuild-easyconfigs v1.8.0.x--squash
Is there a simple way to guess/check the upstream branch that has been used to setup the subtree such that I can make a generic command following the format:
git subtree pull --prefix <path/to/subtree> <subtree-remote> <subtree-branch> --squash
???
Short answer is no.
However, I am seriously considering making a contrib to git to make subtrees write their last push/pull targets to a config file.
You could sort of do a similar hack for now by writing a git hook, which saves which repository was used, and write a wrapper command that uses the saved value.
The subtree documentation sort of boasts it's lack of config files, with the statement:
Unlike submodules, subtrees do not need any special constructions (like .gitmodule files or gitlinks) be present in your repository, and do not force end-users of your repository to do anything special or to understand how subtrees work. Reference: git-subtree.txt
I think that's great that a config is not needed to get the code setup, but at the same time, it wouldn't hurt to have one just to provide meaningful defaults for running the command with fewer arguments.
I'm currently implementing subtree support for tortoisegit, and I'm faced with the same problem. I'd like to make it so when you choose to do a subtree push or pull on a folder, it can remember where that folder was last pushed or pulled from. For now I'm having tortoisegit write to a config file, but it really should be done on the core command.See the pull request discussion here.