GIT Updating subtree: how can I update my subtree?

10,231

Considering that you already set your subtree in your app (git remote add subtree_name [email protected]:user/subtree_proj.git) your have to:

1- Subtree split

git subtree split -P lib -b new_branch_to_split where the lib is the path to your subtree project and the new_branch_to_split will only contain your lib code and will be pushed to your lib repo.

2- Subtree push

git push subtree_name new_branch_to_split:original_subtree_branch(i.e. master)

or

git push subtree_name new_branch_to_split:master

3- Always delete the temporary branch

git branch -D new_branch_to_split

4- Pull the changes in your other project that's using the subtree project

git subtree pull -P lib subtree_name original_subtree_branch(i.e. master)

Share:
10,231

Related videos on Youtube

Arazu
Author by

Arazu

Updated on September 15, 2022

Comments

  • Arazu
    Arazu over 1 year

    We have a few repo's like :

    Site1:

    • lib:

    Site2:

    • lib:

    lib:

    As you see lib is shared in both sites. Now when I use

    [master] git fetch lib
    

    Nothing happens. After that I use :

    [master] git merge --squash -s subtree --no-commit lib
    

    Then it starts deleting loads of files that belongs to the site.

    If I try this: Update the Library Sub-Project from the Shared Library Remote http://www.codeproject.com/Articles/562950/GitplusSubtreeplusMergeplus-e2-80-93TheplusQuickpl

    [master] git checkout lib
    Checking out files: 100% (4521/4521), done.
    Switched to branch 'lib'
    [lib] git pull
    Already up-to-date.
    

    Then just checkout to the master, and run the command:

    git merge --squash -s subtree --no-commit lib
    

    This just deletes a whole load of files from my site and leaves a few files like its in a subfolder of lib.. Why doesen't this just update the lib to the correct version? and leave the files for the site?

    After a reset I do get my project back

    git reset --hard origin/master
    

    How can I update the lib?

    There is a remote branch setup.

    $ git remote -v
    lib     https://github.com/***/lib.git (fetch)
    lib     https://github.com/***/lib.git (push)
    
  • yucer
    yucer almost 8 years
    Can I do this just with local branches ? Without push or pull ?
  • marscher
    marscher about 7 years
    I'd also be interested in this. I've tried read-tree, which fails for "overlapping" files...
  • Miguelgraz
    Miguelgraz about 7 years
    Sorry folks I haven't been working with this git structure for some years already, don't think I'll be able to help any further, really sorry