Heroku: Push to Heroku from local directory instead of GitHub repository

I have an app whose code is in a github repo. I also have a heroku instance that hosts this repository. I can push to it by just committing and doing

git push heroku master

What I want to do is the following:

  1. Commit the local changes
  2. Push to the heroku but NOT to the repository

So basically something like

git push heroku [from local directory instead of master]

Is this possible? I am new to this kind of thing so any help would be appreciated.

Upvotes: 2

Views: 2636

Answers (3)

Mayank Kashyap
Mayank Kashyap

Reputation: 64

Always do your work in a local branch which you can create by

git checkout -b localbranchname

And then push to your heroku master by the command

git push heroku localbranch:master

And all your work on this local branch will be pushed to heroku's master branch and will not get commited to you repository.

You can always switch between you local branch and master branch using the checkout command

git checkout branchname

When you do

git push heroku localbranch:master 

this means that you are pushing to heroku's master branch and from your local branch

Upvotes: 4

mbb
mbb

Reputation: 3110

Heroku doesn't require that push to the remote repository on GitHub before deploying. The following explanation comes from this full how-to:

Branches pushed to Heroku other than master will be ignored by this command.

If you’re working out of another branch locally, you can either merge to master before pushing, or specify that you want to push your local branch to a remote master. To push a branch other than master, use this syntax: $ git push heroku yourbranch:master

So to Zepplock's point, you don't have to push to your GitHub remote at all, just the Heroku remote.

$ git remote -v 
origin  https://github.com/basho-labs/riak-mesos.git (fetch)
origin  https://github.com/basho-labs/riak-mesos.git (push)
heroku  https://git.heroku.com/riak-mesos.git (fetch)
heroku  https://git.heroku.com/riak-mesos.git (push)
$ git push heroku master

^ If your remotes are set as outlined above, you would push your local copy of master to Heroku, not the origin master. Alternatively, you could choose a different branch:

$ git checkout -b not-master-branch
$ git push heroku not-master-branch:master

Upvotes: 3

Zepplock
Zepplock

Reputation: 29135

When you do git push heroku master you are in fact pushing your local code/branch.

If you want to push from other branch than master you need to checkout that branch locally first and then do a push.

Upvotes: 1

Related Questions