Push to Other Branch Git - ruby-on-rails

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.

Related

Heroku app seems to be pulling from wrong Git respository/branch

My problem seems to be due to my lack of understanding with how Git and Heroku communicate, but here it is:
I have/had two Heroku apps running fine for the same project - one staging and one production. Originally, I had both apps connected to the same master branch in my Git repository. I'd just push all staging changes up to the staging app with git push heroku-staging master, and when I wanted to push up to the production app, I'd just run git push heroku master.
For clarity, these are my remotes. I replaced my app with my-app:
heroku https://git.heroku.com/my-app.git (fetch)
heroku https://git.heroku.com/my-app.git (push)
heroku-staging git#heroku.com:my-app-staging.git (fetch)
heroku-staging git#heroku.com:my-app-staging.git (push)
origin git#github.com:My-app/my-app.git (fetch)
origin git#github.com:My-app/my-app.git (push)
And here are my branches:
dev cbafa55 added new badge
master cb5f4c4 split seeds into different services
* staging cbafa55 added new badge
Recently, I realized I should keep all my staging changes in a separate staging branch on my repository, and keep my production environment at one spot in the master branch.
So I'm now using a staging branch in the repository (which already existed but wasn't being used) for everything I want to throw up to the staging app, and the master branch will be used for the production app.
I had some trouble getting the staging branch to match what I have locally, so I just used git reset --hard (commit_id), where the commit_id was the last commit I made that I was satisfied with. So at this point, my staging branch in the git repo matches perfectly with where I want it, and I confirmed on github, to make sure everything on the staging branch is the same.
But when I push up to heroku-staging now, it seems to still be pulling from the master branch. Even though I'm currently in my staging branch, and pushing from there. I added everything, and committed everything, but when I push it up, it tells me everything is up to date, and on my staging app, I see a fairly old familiar error in the logs (just something I remember screwing up in the application itself). When I look at my staging branch, though, it doesn't have the code that produces that error. However, my master branch does still have the code that produces that error (since I haven't pushed to the master branch in a while).
I've tried using git push heroku-staging staging, and git push heroku-staging master, both from my local staging branch (which has all my current changes), both of which yield a message that says everything is up to date. I'm not sure exactly how heroku apps make the connection to branches, but these are the only two options I can think of.
I also looked at the activity of my app on the heroku dashboard, and it says the most recent build was successful, and deployed cb5f4c4, which is the most recent commit from my master branch (which I don't want). This makes sense, my heroku-staging app is producing that error that exists on the master branch, but I'm not sure why it's using this commit.
Apologies for the novel of a question, but just wanted to be thorough with the things I've done/tried.
I've hit a wall, and can't think of any more ideas. Any thoughts?
Seems like you need this:
git push heroku-staging staging:master
which will push all the changes from your local staging branch into your remote master of heroku-staging.
See this stackoverflow post for more information about how to push different local git branches to heroku.
If you want to push the changes in your staging branch to your Heroku staging site configured as git remote heroku-staging you need to do:
git push heroku-staging staging:master
Heroku will only deploy the master branch so you need to push your local staging branch to the remote master. It looks a little weird but this is just the git command for pushing a local branch into a different remote branch.

How to have Heroku build my development branch on a staging server?

I have a production application on master branch running all fine on heroku. I would like to run a second Heroku application but 'fed' from a local staging branch. These are the commands that i've run in my failed attempt to do this:
git checkout -b develop
heroku create --remote staging
git push staging develop
But because i'm pushing from a 'non master' branch it doesn't build the app;
remote: Pushed to non-master branch, skipping build.
I have read the managing multiple environments doc here; https://devcenter.heroku.com/articles/multiple-environments but it does not seem to address what I'm trying to achieve, rather merging develop branch into master first then pushing master to remote staging. I want to push my develop branch to a staging app and have it running live in RAILS_ENV=production mode, iteratively push to this live 'staging/testing' app then when i'm really comfy with what i'm going i'll merge the develop branch code into the master branch and push to the primary mast app.
Can anyone help me with how to achieve this?
as per heroku doc
git push staging develop:master
as per Git documentaion
git push <REMOTENAME> <LOCALBRANCHNAME>:<REMOTEBRANCHNAME>
so
git push heroku staging:master
means
push my staging local branch to master remote heroku branch
Its not as close to the most direct command line - but my DevOps pipeline using Codeship makes this much easier for commits on different branches.
I have Codeship automatically deploy anything to the dev branch to one Heroku app, anything in the staging branch to another, and anything to master to the live branch.
Not the direct solution you were probably looking for - but something that shows the benefits of a good CI setup!

Git Errors when Pushing on Heroku

I'm using Heroku and have a Rails app that is stable (production env), so I wanted to create something new where I can have quality assurance env where I can see how the changes will work on Heroku (as well as aggregating enhancements for releases) without always pushing to my production app.
So what I did was create a new Heroku app, and also create a new branch locally (dev). My intention was to merge dev into master locally after I tested the change on my new Heroku QA app, and then push to Heroku production from my master branch.
My approach might be a bad one with my landscape, I'm a newbie, so this was just my best guess at how to do this.
But when I pushed my dev branch to my new QA app, it worked for pushing to a dev branch of the QA app, but not the master. So I couldn't see (and test) my changes on the new QA app. It seems to be telling me that I can only push the master branch to the master of my QA app, since I pulled already and everything was already up-to-date, but I receive this error:
Pushing to git#github.com:foobar/QA.git
To git#github.com:foobar/QA.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:foobar/QA.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Can someone please help me figure out what I'm doing wrong - either with my environments or with Git? Thank you.
Try pushing with the -ff (fast-forward) option: git push heroku master -ff (replace heroku with the actual name of heroku remote).
Heroku apps only run off of the master branch of the app repository (local to Heroku). If you want to deploy a branch to Heroku which isn't the master branch of your local repo, then you need to specify it. In your case it would be something like git push qa-remote dev:master (replace qa-remote with the actual name of the remote to your QA app), which says push my local dev branch to the master branch on qa-remote.
When you push like that for the first time, you'll likely need to add the -f flag to force push (non-fast-forward). Subsequently you should be able to push without the -f flag, as long as your local branch is up-to-date.
Use the following command to push the update forcefully git push -f heroku master

update files from local to remote with git and capistrano

I have deployed my app in remote server with capistrano and git. I'm novice with capistrano and git, and my question is:
e.g.
I make a change and add code in any file from my local project, e.g. change 2 lines in controller or model or view or css or js or routes.rb or devise.rb...etc.
before I had a ftp and replace the files via ftp, I see that this way is not good for rails.
I want to know how can I send those changes to my production remote app in my vps remote server.
I have tried:
cap deploy
but is very very slowly and overload the server. I dont think that is way is correct
I dont know if this must be doing with capistrano or with git e.g. I suposse with git is:
git remote add origin user#ip.ip.ip.ip/~/project
git push origin master
Its possible use this code for deploy changes in production app in remote server? or have I that use capistrano for make changes in app in production server?
Sorry for mi ignorance but I'm novice with rails and capistrano and git.
Thank you
You can deploy code using either just git itself or with capistrano (together with git).
Using just Git
You only need to run "git remote add origin user#ip.ip.ip.ip/~/project" one time, after this your settings are already saved. If you want to see your remote git repos, just type "git remote"
After you have made your changes and run git commit (I assume you know how to do this already), then run "git push origin master" to push all your changes to the remote repo.
Now SSH to your remote server, eg "ssh myuser#mydomain.com" (for Mac) or using Putty (for Windows)
Once logged in to the remote server, navigate to your app root folder.
if you have never cloned your git repo to your remote server before, you will first need to run "git clone "
otherwise, just run "git pull origin master". This will fetch and pull the changes from Step 2 above to your remote server. And now you are finished!
Advantage: This approach only pulls your most recent changes to your remote server, so it is much faster.
Disadvantage: You have to manually run a lot of commands to SSH to server and git pull.
Using Capistrano
You mention you can run "cap deploy" so I assume your Capistrano setup is fine. This approach is slower because it pulls your latest commit (and potentially your whole git repo) when you deploy.
If you want to speed up your Capistrano deployment, you can add the following to your deploy.rb. This keeps a copy of your git repo on your remote server instead of doing a full git clone upon every deploy.
set :deploy_via, :remote_cache
Advantage: Just type "cap deploy" and deployment happens (plus all the capistrano benefits of deployment rollback etc)
Disadvantage: Slower than just git pull.

Backing up work on a branch using heroku, rails and git

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.

Resources