Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding git subtree from a branch

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?

like image 758
Geoff Ryan Avatar asked May 30 '13 06:05

Geoff Ryan


People also ask

What is git subtree push?

git subtree split lets you specify a rev other than HEAD. ' git push '(man) lets you specify a mapping between a local thing and a remot ref. So smash those together, and have git subtree push let you specify which local thing to run split on and push the result of that split to the remote ref.

How does git Subtrees work?

git subtree allows you to nest a repository as a subdirectory inside another. It's one of the various options for managing project dependencies in Git projects. You add a subtree to an existing repository where the subtree is a reference to another repository URL and branch/tag when you wish to utilize it.

What is prefix in git subtree?

The –prefix parameter defines the root directory for the cloned repository, then add the remote url, the branch and let it squash the entire commit history (–squash). Git doesn't like uncommitted changes so make sure to stash/commit any existing changes before adding a new subtree.


1 Answers

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.

like image 60
gipi Avatar answered Oct 13 '22 01:10

gipi