0

This is a follow up to Deploying to Heroku using git on bitbucket.

I am not new to Ruby on Rails (RoR). I am new to git, Heroku, and Bitbucket. I'm missing some fundamental concepts I am just not getting reading books and playing around.

I have followed along with https://devcenter.heroku.com/articles/getting-started-with-jruby#introduction. It has been invaluable in getting me started with deploying RoR to Heroku. If I follow along closely, things work. My questions below assume everything in that tutorial is working correctly.

I'm hoping these very basic questions will help others facing the same learning challenges I am.

My first basic question: Are Heroku repositories private by default?

My second basic question: What does the heroku command do? Sometimes it seems to run something on the server as in heroku config:set MY_VARIABLE=MY_VALUE which, I think, sets an environment variable on the server running my website. Sometimes it seems to run things on my devlopement (i.e. local) machine as in heroku local web -f Procfile.windows

For the sake of argument, assume a Heroku repository is not private and I want to host my repository (repo) on Bitbucket.

After installing the Heroku toolbelt, I have done a git clone https://github.com/heroku/jruby-getting-started.git myProject from a command processor.

Ok, I understand the "git clone". If my current working directory is f:\x then the clone operation will create f:\x\myProject (and subdirectories) complete with sample code as well as a repository.

I make and save my changes to the local (sample) files (e.g. f:\x\myProject\app\views\index.erb) with my favorite text editor. (In my case, the Atom text editor.)

I do http://localhost:5000 allows me to see myProject on a local browser. This works fine.

I then do a

    git add .
    git commit -m "Some comment"
    git push heroku master
    heroku open

So now I pushed the changed sample code to Heroku. The heroku open opens a new tab in my web browser. Magically, myProject.heroku.com is now working with the changes I made to f:\x\myProject\app\views\index.erb.

Assume I want to host my repository on Bitbucket.

Now I get lost. Do I clone f:\x\myProject to Bitbucket? Do I push to Bitbucket?

I note from https://devcenter.heroku.com/articles/git

Before you can push an app to Heroku, you’ll need to initialize a local Git repository and commit your files to it. For example, if you have an app in a directory, myapp, then create a new repository for it:

Is that really true? Is there no way to push from Bitbucket to Heroku without having a repository on Heroku?

I'm running Windows 7 with Cygwin and Heroku's toolbelt installed. What tool do I use to create and copy my local repository to Bitbucket?

Once I have a repo on Bitbucket, what tool and git commands do I use to place my code on Heroku without creating a repo on Heroku or updating the repo?

Thank you.

Community
  • 1
  • 1
RalphShnelvar
  • 557
  • 1
  • 6
  • 17
  • you're using heroku as a production server, not a repository. you have a local git repository on your computer. Github and bitbucket are examples of places where people host "public" (as opposed to local) repositories. – toddmetheny Feb 27 '16 at 21:35
  • I thought bitbucket had private repositories by default and github had public repositories by default – RalphShnelvar Feb 27 '16 at 22:18
  • It doesn't matter if it's public/private. It's just a repository hosted on the internet so people can collaborate from it. You have a version of git on your local machine. That's where you're pushing to heroku from. – toddmetheny Feb 27 '16 at 22:23

2 Answers2

0

You're actually pushing to heroku from your local git repository. You could actually push to heroku without github or bitbucket. It doesn't matter which one you're using. Heroku is a separate thing relative to your public repository. Type git remote in your terminal (from your app directory) and it'll show you what remotes are connected. You likely have one called 'origin' which is typically github and one named 'heroku' which is heroku. Hope this helps.

toddmetheny
  • 4,405
  • 1
  • 22
  • 39
  • I'm still trying to understand what's going on. When I do `git remote` I get herokuorigin-bitbucket origin-heroku – RalphShnelvar Feb 27 '16 at 22:22
  • @RalphShnelvar git is just a version control system. You can commit something to git on your local machine, and then push that version of the app to heroku without sending it to a repo that lives on the internet, such as bitbucket or github. Bitbucket and github are just services for hosting repositories online so groups of people can collaborate on the same code. – toddmetheny Feb 27 '16 at 22:27
  • Sigh ... sorry for the previous "comment". What I'm trying to understand is "Is there a way to copy code from, for example, the tip of my current branch to Heroku's server without creating a repo on Heroku's server? Ok, I see @karma_police 's comment but ... how does one do what karma_police suggests? Assuming I want to save a repo on Bitbucket, what command do I run - and where do I run it! - to get the code from bitbucket to heroku? – RalphShnelvar Feb 27 '16 at 22:38
  • @RalphShnelvar I don't understand the question. You don't create repos on Heroku's server. That's where the application code in the repo gets deployed to. I don't know what you mean by the "tip" of your current branch. The only way to get code from your local branch to heroku is to deploy it. If you mean you're trying to deploy a branch other than master it's $ git push heroku name_of_your_branch:master More here: https://devcenter.heroku.com/articles/git – toddmetheny Feb 27 '16 at 22:47
  • "branch tip" ... I'm using the terminology I found on pages 3 and 19 of O'reilly's Git Pocket Guide. What's confusing me, then, is that I cloned a repo from Heroku. Your comment of "You don't create repos on Heroku's server" just made a bunch of things click, I think. Thanks! – RalphShnelvar Feb 27 '16 at 23:01
  • comment from @karma_police of "You don't create repos on Heroku's server" has just confused me again. From https://devcenter.heroku.com/articles/getting-started-with-jruby#deploy-the-app I read "When you create an app, a Git remote (called heroku) is also created and associated with your local Git repository." ... Is this remote on their server or on my local machine? – RalphShnelvar Feb 27 '16 at 23:39
0

When you push your repo (local or cloud-based) to Heroku, Heroku receives your code and supporting files into a repository located at Heroku; then it builds it into a slug that it can run. The files are retained in the repository located at Heroku after the slug is built. You can clone the repository at Heroku onto another local machine if you want to.

However, Heroku recommends that you maintain a canonical source repo somewhere other than at Heroku. Canonical basically means the true source to make copies from.

I have avoided using the word git because git it is a command, a cloud based repo service (github), and is also a git repo on your local development machine. That is confusing to me. I have also avoided using the word remote, because a git remote is a pointer to another repository which could be local or remote. People also say 'remote repo' meaning a repo that is not local, but from the git program's perspective, a remote is just a pointer to a repo other than the one you are currently working on in the git program. A git program could be operated from the command line, or a graphical interface on your local machine; or on a cloud based system. I hope I got this mostly right.