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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With