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.
Related
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!
I have an instance at heroku where I push the different branches of the same project for testing. Since the branches are different (although they are created off the main, develop branch) and it's only for testing, whenever I push to it I'd like that new "push" completely rewrite code there without any merging, conflicts, etc. In other worlds, I'd like kind of truncate (or recreate) my repository at heroku each time before pushing.
Is it possible?
You can try git push heroku master --force or if you would like to deploy a specific branch, then git push heroku <branchname>:master --force
I want to push code on heroku that is on gihub
I used the following command
git push heroku mybranch:master
The error is
To https://github.com/user/lyricle-new.git
! [rejected] lyricle-frt-backend -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/user/app.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Used the command git pull as mentioned in hint the response was Already up-to-date.
What could be the reasons behind this error? and is this the correct way to push on heroku
By doing git push heroku mybranch:master, you are telling git to take your local mybranch branch and merge it with the remote master branch (remotely stored on your heroku repo).
You get an error because master is ahead of mybranch in terms of commits.
Consider this example:
master: --------b---------m---------
mybranch:........\-c--c--/...........
At some point, you branch (b) master into mybranch, commit (c) some code to the branch, and merge (m) it back to master.
Now consider this example:
master: --c-----b---c-----m---c--
mybranch:........\-c--c---/.......
It is pretty much the same scenario but while you were committing code to mybranch, someone updated master by committing some other code. If you were to merge back mybranch into master, you would risk causing conflicts between your code and the new code contained in master, thus Git refuses to do the merge. First, you have to update your local branch with the new version of master and then only Git will allow you to push.
In short:
- git pull heroku master:mybranch
- resolve potential conflicts
- commit modified files
- git push heroku mybranch:master
Now about Heroku, you are supposed to always push code like this: git push heroku master (considering you are on the master branch locally). What you should do to avoid things like git push heroku mybranch:master is, when you finish working on a branch, always merge your changes to master and then (after verifying that everything is working) push master to heroku.
See this resource for a simple git workflow that seem to be what you are looking for: https://www.atlassian.com/git/workflows#!workflow-feature-branch
Everything is centralized in master eventually, and you can then regularly push master to heroku (ideally you would push once for every version of your app)
From the hints it seems that you have not pushed your latest changes to your remote repository.if you have done a pull and pushed again maybe you have removed files in your local repository that you did not remove in your remote repository.try doing a git add --all and then commit and push the changes.
I am collaborating on a project and cloned the repo from Github, made some changes and pushed to Heroku. Now the cloned app had all of its keys and passwords hardcoded, not in ENV variables.
So I created ENV variables, added the file to .gitignore. So this app still has these keys in the commit history. What I have done now is have the author create a new repo on Github, remove .git file from original app and push new code to new repo.
So now I have cloned the new app, added a new remote the the Heroku app.
heroku git:remote -a myapplication
My issue is I cannot push the new app to the existing Heroku app. When I do I get:
error: failed to push some refs to 'git#heroku.com:myapplication.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.
So a git pull says everything is up to date.
git remote -v outputs
heroku git#heroku.com:myapplication.git (fetch)
heroku git#heroku.com:myapplication.git (push)
origin git#github.com:author/myapplication.git (fetch)
origin git#github.com:author/myapplication.git (push)
What can I do to push the new application to the existing heroku app?
Update
I ran
git push -f heroku master
which pushed but I had error
you have not declared a Ruby version in your Gemfile.
To set your Ruby version add this line to your Gemfile:"
ruby '1.9.2'"
I've never had to specify before, and now all the original config vars that where set are no longer stored in Heroku.
git pull would pull by default from GitHub, which has all your commits already.
You might need to:
git pull heroku
clean-up the files (if the merge brings back the hardcoded values)
push to origin
push to heroku through the heroku command.
Git uses the concept of tracked branch to know which remote branch is linked to a local branch.
In your case, you probably have your local branch (I suppose it's master) linked to origin/master. So, when you do a git pull, Git is trying to get new stuff from git#github.com:author/myapplication.git, which is not the wanted behavior.
You have to change your tracked branch using :
git branch --set-upstream-to heroku/my_branch
Then, you can do a git pull which will now have the wanted behavior. Then just push to heroku, as you always do.
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