Rails/Heroku/Git newbie - here is my question. I have an app deployed with Heroku and am using the git repository hosted there as the only remote copy of my local work. I start making changes locally on a new branch and want to make this branch available on Heroku so that I can continue work on it from another computer. Heroku ignores branches other than master and I don't want to merge my changes yet (or push them as master). Is there a way to store/access my new branch via my Heroku git repository, or is it better to have another remote git repository for my work in progress.
Thanks!
You can push a local branch to the remote git server with:
git push origin branch_name
That way, you can pull it down again elsewhere with:
git checkout -b branch_name origin/branch_name
http://gitready.com/beginner/2009/02/02/push-and-delete-branches.html
http://gitready.com/intermediate/2009/01/09/checkout-remote-tracked-branch.html
I would go with a separate git repository as suggested - github.com or similar. Store your code there and deploy to Heroku's master repo - Heroku is a hosting platform afterall not a home for your repos.
ALTERNATIVELY Make use of dropbox and create your local workspace in a dropbox folder that is synced across multiple computers - I employ this method as well as git - plus you get the advantage that Dropbox is versioned so if you delete/change a file that you haven't committed yet you can get it back.
Related
I'm new to programming, learnt languages but this part I have no clue.
I'm working on a app that is on bitbucket and on Heroku cloud.
I am not exactly very clear how the bibucket repository interacts with Heroku and also my local offline commandprompt+sublimetext+PG database.
So what I'm doing is i have made some changes physically on Bitbucket (manually on their website) based on the changes Ive made and viewed (offline on localhost 3000) and wanted to push it to Heroku to have the changes online. There does not seem to be any buttons on bitbucket for that purposes and I guess I have to do it through the command prompt.
In that case how do I make those changes (command lines) and update the sublime+PG on the local server? I seen a few codes on git and suspect those are it (like git push -v) which lists the repositories but I don't wish to test and end up screwing the codes. Please advise if there are easier to do any of the above.
Note that I want the changes to be on Heroku because of this error.
Rails 4 Relationship Issue extended
Also what the difference between pulling and pushing changes? I'm reading the git definitions but it isn't saying much. Just that pull is pulling data from other repository to I'm not sure where. Push is to update remote refs with associated objects.
Many thanks!
Because you're new, let me explain what you need:
Heroku uses an amazing deployment process which based on the git scm
system. This means that you just need to "push" your git
respository to Heroku in order for it to deploy your latest revision
of code
The problem you cited is you're trying to push from bitbucket
directly. Bitbucket / github are essentially just cloud
repositories where you can store your code, and is not where Heroku
can "read" your files from
To get this working, as you've stated in your comments, you need to push from your computer. This is achieved by creating a remote repository for Heroku, and then pushing to that, like this:
$ git remote add heroku git#heroku.com:yourherokuapp.git
$ git add .
$ git commit -a -m "Latest Commit"
$ git push heroku master
I have two computers and want to use only one for deployment.
I regularly do push to my private git repo on another computer and on the current computer I do both push to git repo and deploy to heroku.
If I made changes on another computer (such as adding new files) and push to git repo, then pull these into yet another computer then push back to git repo then push to heroku, would my changes on the first computer (the new file for example) deploy correctly to heroku?
I currently have a remote to an EC2 instance set up on on my local git repo. The push works.
git push remote_name master
Delta compression using up to 4 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (12/12), 896 bytes | 0 bytes/s, done.
Total 12 (delta 6), reused 0 (delta 0)
To user_name#dns:eko_web.git
4342c41..7bbc7db master -> master
When I ssh into the remote EC2 I can find the very first push I made copied over my app to var/app/current/ but no further updates. When I look in my bare git repo I find my most recent pushes when I do git show HEAD:<some_file>. When I manually edit the view in var/app/current the change isn't reflected in my website; the same initial push is all I see. I have a hook set-up in the post-receive of the bare git repo that is the following:
#!bin/sh
GIT_WORK_TREE=/var/app/current git checkout -f
As a broad overview, I used the following tutorials to get me this far. http://myrailslearnings.wordpress.com/2013/02/19/getting-ec2-to-use-git-for-rails-app/ http://www.lovholm.net/2013/06/26/push-your-code-onto-your-ec2-instance-with-git/
Thanks for any thoughts on this!
Edit:
Per Rico's suggestion, I started a new instance that hadn't been initialized with Beanstalk. I now have a git repo on the instance that (when updated manually) reflects changes on the server. But I'm still having problems pushing remotely to that location; it shows a successful push but then the files are there but not committed. If I commit them manually and then restart the server the website is updated.
There are many ways you can do the deployment. Deploying by pushing directly to a non-bare git repo can be done but it's not that common. (Like http://www.lovholm.net/2013/06/26/push-your-code-onto-your-ec2-instance-with-git/ describes) There are things that you have to watch for. For example you cannot push to a remote repository branch if that branch happens to be checked out.
From the looks of it you were deploying through Elastic Beanstalk initially or something because /var/app/current is the default location where it deploys Rails apps (when you do a git aws.push) Keep in mind that in a regular Elastic Beanstalk deployment /var/app/current doesn't hold a git repo. It's just a copy of your code (The git repo is saved somewhere else, I believe in S3)
The most common way of deploying from git is to have your git repo in github, bitbucket or a git repository in the cloud. Let's say you use github. At deploy time you would push to the github repository and then the new code gets deployed by cloning or pulling from the github repository into your cloud server. Capistrano is one of the tools that automates this process.
Another way of deploying is pushing to a bare git repository in the same say EC2 server where you are deploying and then pull/clone from that bare repository into another non-bare repository in the same server.
In your case you can also try switching your remote repository to non-bare if you want to see the code there. Easiest way I guess is deleting your bare repository and then cloning the original as a non-bare repository and sticking it where you want to deploy your code.
I'm working on a rails app that I occasionally push to a staging server to test things out. I can easily push my local master to the remote master (I called it origin). I'm running into a problem where I'm trying out 2 frameworks, each in their own branch on my local machine. I'd like to see how the frameworks work on the remote server.
How can I push from local:Framework1 to remote:master (because the staging server has scripts that deploy master from the staging server's git repo)?
git push origin Framework1:refs/heads/master should do the trick.
Merge Framework1 into local master, then push origin master. You'll need to perform a clean merge locally before you start mucking up the remote server anyway.
I have a Rails app deployed on Heroku and I have a git repo that I'm currently working on with uncommitted code changes. In the meantime, I need to make changes to the source on Heroku independently of the local repo. Can I do the following:
Clone the Heroku git repo on the same development machine with a different app name though with the same account
Make changes to the new local repo
Commit those changes to the new local repo
Push those changes to the Heroku repo
Resume working on my original local repo
Will this approach work?
Yep, that workflow would work, or stash them - and don't forget if you do make a clone of the heroku repo you'll have made changes to a different clone of the repo and you'll need to make those changes in your original local repo.
In future I'd suggest that you assume that your 'master' branch is what's live on Heroku and branch of that to work in - you can even push this branch into a new app for testing purposes. This way bug fixes can be performed on your local master branch (or another branch and merged into master) and pushed to heroku and then when you've finished your new work you merge the branch back into master and deploy that to your live environment. I wrote a blog article on the subject a while back, here
I haven't used heroku but if I wanted to make changes to a deployed application while I had unsaved changes in my sandbox, I would do one of the following.
stash my local changes, cut a branch from the point where I want to make a fix, make it, deploy it, switch back to my original branch and pop from the stash.
Commit my unsaved changes (into the current branch - say work), cut a branch from the point where I want to make a fix, make my fix, deploy it, switch back to work, reset my HEAD to before my "temporary" commit and resume work.
Unless you're using git in an unconventional fashion, there's no need to make another clone.
If you clone the heroku repository to a separate directory, made changes and push it from there, then there is a possibility of conflicts later down the road.
If its only the issue with the uncommitted changes then certainly you can stash them using "git stash" and later retrieve it using "git stash pop".
My work-cycle: I always keep a master branch with the #1 rule "always push to Heroku after committing something to master". If I code on something that I do not want to deploy immediately, I have to branch.
I know this works not for all use cases, but having always a branch that is identical to the app that is productive on Heroku makes me sleep better ;)