Trouble pushing changes to remote Git repo - ruby-on-rails

I have started learning Ruby on Rails and Git.
Whenever I try to push any changes to my remote repo on Github, I encounter the following error:
C:\Sites\first>git push origin master
To git#github.com:piy9/Twitter_clone.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:piy9/Twitter_clone.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.
NOte: I have added all the files in the directory and committed the changes. I have not created any separate branches using pull or checkout.
I am not asking for a solution to the problem.
doing
git push -f or
git push origin +HEAD
worked for me.
What I want to know is, why am I getting the error while trying to push to the original branch.

follow this and get everything works....
git branch production
git checkout production
#do some code changes
git commit -am "some desparate code changes to try fix heroku"
git push heroku production:master
Note: this will get your work done and will leave your previous branch.
or you can try this one also git push heroku +master

Looks like remote branch is ahead of yours, which means it contains something your local branch does not have. You may easily see commits on remote branch since when local branch was created or updated (assuming you run "git fetch origin/master" to fetch remote changes first):
git diff HEAD...origin/master
The output will answer your question why you are getting the error.
Now, my guess about the reason of the problem you have is that either someone has access to remote and pushed something, or you modified something using github editing interface and committed since last checkout/pull/merge. Using forced push as you did is not a good approach and it messes the history, it basically overwrites the remote branch with your copy, ignoring any remote changes.

Related

Git Push Heroku Master rejected, even though everything up to date

I'm really confused -- I have made some changes to my app, and need to push the changes to heroku.
I have run git add . git commit -m "message", and git push origin master (all my work is on master branch), and get the message saying Everything up to date.
HOWEVER, when I run git push heroku master immediately after, I get a message saying Updates were rejected because the tip of your current branch is behind its remote counterpart. Integrate the remote changes (e.g. 'git pull ...') before pushing again.
When I run git pull origin master, it says Already up-to-date. So I'm really baffled as to what is behind here, or what I need to do!
use source-tree and check the file status and then try to push.
https://www.sourcetreeapp.com/

code push to heroku not working

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.

Remote branch ahead of local branch; can't push

I'm trying to push to heroku, but I recently dropped back a few commits as the production and local code were both flawed. Now I'm getting the error:
Updates were rejected because the tip of your current branch is behind its remote counterpart. Merge the remote changes (e.g. 'git pull') before pushing again.
I don't want to pull from the remote, but rather push the code I have locally.
How can I do that?
I'm an idiot. I went back and read the next line.
If it helps anyone in the future, the answer is to use --force:
git push heroku master -f

pushed to heroku but no changes to app?

I used the following three commands to push the changes to an already existing app but the changes are not being reflected
$ git add .
$ git commit -m "changes"
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
$ git push heroku master
And I get:
To git#heroku.com:sleepy-oasis-7771.git ! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#heroku.com:sleepy-oasis-7771.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
and no changes are reflected in the app
Your push was ! [rejected]. That's why no changes take effect.
As the message indicates:
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
This refers you to further documentation, visible on your local machine or online. Again, as the message indicates, a git pull (and its resulting merge) will fix this issue.
One way to avoid this problem is by using a rebase workflow instead of a merge workflow. Do your development in a feature branch, and when you're ready to merge, pull master, rebase the feature branch, re-run your test suite, and then merge.
Also, please read your error messages.

Heroku: how to "git pull" after 'git push -f'

I got this error message (copied below) after trying to push to Heroku. I initially set up a facebook canvas app and selected the hosting on heroku options. It gave me a heroku url, which I added as a remote on the app I was developing on my machine
heroku git:remote -a desolate-springs-1684
But when I pushed, I got this error
error: failed to push some refs to 'git#heroku.com:desolate-springs-1684.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
localhost:nhl michaelmitchell$
So I did
git push -f heroku master
But now I apparently have to do a 'git pull'. However, what do i put after the 'git pull'? The name of the heroku url? or something else?
Forcing your git push was not a good idea because you lost any commit that was done by you or other collaborators you were missing on your working copy.
Before pushing, you should have either merged or rebased the upstream changes into your local working copy.
To merge the changes locally
$ git pull heroku master
$ git push heroku master
To rebase the changes locally
$ git pull --rebase heroku master
$ git push heroku master
BTW, now that you have pushed your changes, you actually don't need to do anything else. The remote repository already contains all your changes.
If for whatever reason the $ git status command is returning outdated references, simply run
$ git pull heroku
to fetch all the remote changes. Please note that unless you specify a target branch (or you have the tracking branch enabled), git pull will simply download (and not merge) the upstream changes.
Also note that Heroku should not be considered a git hosting. It means that it's extremely uncommon to perform a git pull from Heroku. Instead, you should use a git hosting (such as GitHub or BitBucket) to store your repository and only perform push to Heroku to deploy the application.
That error basically means that there is code in the repo that is newer than the code you're trying to push to it.
you have to do a pull and update your own working repository then push again, or just force a push
git pull heroku master
As a side note, if you aren't familiar with all the git commands, I would recommend you use a GUI as it may make the whole process a lot less overwhelming.
There are plenty of great clients here: http://git-scm.com/downloads/guis

Resources