Adding git subtree from a branch

Geoff Ryan picture Geoff Ryan · May 30, 2013 · Viewed 10k times · Source

I'm trying to add a repo (called cow) to my project using git subtree add. In particular, I'd like to add the branch stable (which is not the master branch). I tried:

git subtree add -P cow https://github.com/geoffryan/cow.git stable

But this returned the error

'stable' does not refer to a commit.

I also tried:

git subtree add -P cow https://github.com/geoffryan/cow.git cow/stable
'cow/stable' does not refer to a commit.

And:

git subtree add -P cow https://github.com/geoffryan/cow.git ca26d248a12c21264e32a2c212381cafb578c9fb
'ca26d248a12c21264e32a2c212381cafb578c9fb' does not refer to a commit.

The hash was that for the latest commit in the stable branch. The examples of use I've seen online all use master for the commit, is it possible to use subtree add on a non-master branch?

Answer

gipi picture gipi · May 30, 2013

This seems to work

$ git remote add cow https://github.com/geoffryan/cow.git
$ git fetch cow
$ git subtree add -P cow cow/stable
Added dir 'cow'

I don't understand how to use directly the command with the repository part.