GIT Updating subree: how can I update my subtree?

We have a few repo’s like :


  • 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

[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***/lib.git (fetch)
lib***/lib.git (push)

  • Git and TortoiseSVN, how do i undo my changes in local repository without cloning the remote repo again
  • commiting to git repo from a second machine
  • How to push only to a branch of my fork of a Github repo, after a pull request has already been made
  • How to push to the Git repository after git clone?
  • Change Github's Default Gist Styles
  • Can git checkout to remote branch without pulling files?
  • Commit pushed, no new release. How to update composer?
  • Update pull request of deleted fork
  • One Solution collect form web for “GIT Updating subree: how can I update my subtree?”

    Considering that you already set your subtree in your app (git remote add subtree_name 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)


    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)

    Git Baby is a git and github fan, let's start git clone.