How to push to git subtree?

Philip Kirkbride picture Philip Kirkbride · Feb 3, 2017 · Viewed 12.3k times · Source

I added a subtree on git which seems to be working. I went into the directory and made some changes and then pushed.

I noticed these changes show up in the parent project but the repository which I used as the source hasn't been updated.

I tried git subtree push which returns:

You must provide the --prefix option.

Also git subtree push --prefix=my/folder [email protected] which returns:

You must provide <repository> <ref>

What is the correct way to push changes to the origin repo for my git subtree?

Edit: it was suggested that I do:

git subtree push --prefix=my/folder origin master

When I run the above it starts the process but ends up saying the branch is behind. So I run:

git subtree pull --prefix=my/folder origin master

Which returns "Already up to date"

Answer

Dan picture Dan · Feb 3, 2017

So, with some joint effort with @PhilipKirkbride, here's what we managed to figure out:

You need to put all the details in the command:

git subtree push --prefix=my/folder subtree_origin master

Where master is the branch in the subtree, and subtree_origin is just another remote, which happens to point to your subtree's git repository. You can also type the full repo URL.