Robert Moskal
Robert Moskal

Reputation: 22553

How to push a subtree to heroku using a non master branch

I know I can do this:

git subtree push --prefix server heroku master

to push a subtree of my project (in this case everything under the ./server directory).

And I can do the following to push a non master branch:

git push heroku somebranch:master

But I cannot seem to do any combination that looks like this to push a non master subtree:

git subtree push --prefix server heroku somebranch:master

I get:

'somebranch:master' does not look like a ref

I would so like to do this!

Upvotes: 9

Views: 2482

Answers (2)

Martin Moss
Martin Moss

Reputation: 63

The above answer will eventually run into problems.. When other people push. You can use the following command - I make it an alias - which will achieve the same aim, but allow deployments by multiple people.

git push heroku $(git subtree split --prefix=server $(git symbolic-ref --short -q HEAD)):master --force

Upvotes: 3

Chris
Chris

Reputation: 136958

On my machine running Git 2.7.1 the documentation for git subtree push says

Does a split (see below) using the <prefix> supplied and then does a git push to push the result to the repository and ref. This can be used to push your subtree to different branches of the remote repository.

There is little mention of branches at all in the documentation for git subtree, and none of the cases where branches are mentioned fit your use case.

Reading between the lines it looks like the source branch is whatever you have checked out:

git checkout somebranch
git subtree push --prefix server heroku master

And indeed you confirmed in comments that this works.

Upvotes: 8

Related Questions