My live site was updated since my last commit, and I haven't made any local changes, so I want to just push everything that's live up to my Git repo.
However, when I try to push from my live site, I get:
error: failed to push some refs to 'https://username:password#bitbucket.org/myrepo/myrepo.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.
How can I push without doing a pull?
PS - I tried doing a git pull force from the live server, and it wiped out my previous commits, so I can't do that
I see two ways doing this :
If you wish to really lose all the commits pushed before yours, use "push -f" to force erasing the history.
If you wish to keep both commits, you may try a "git fetch" and then a "git rebase" in order to keep everyone's changes.
Related
Frequently (especially with commits using --amend) I push to heroku using git push heroku master --force. I do this because I get an issue when trying to push without force..
issue:
o https://git.heroku.com/site.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.heroku.com/site.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I see no harm in it because my remote repository and local repository are fine. Am I wrong?
This warning happens because the commits are different and thus your repository cannot ensure data preservation, it is bad practice since it could lead to code data loss, as long as you know it won't, Heroku itself will not have a problem as all it does is take the code in the master branch and deploy it, regardless of previous states.
I have been trying to push my app to heroku using git push heroku master
but I keep getting this error message. what should I do?
error: failed to push some refs to 'https://git.heroku.com/raad-photo-app.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Related Image
You must pull latest changes from the remote before you can push.
Someone added new code which you don't have locally do you must grab it first.
Read this question to understand what is pull and why do you need it.
Local branch behind remote branch (pull, rebase, fetch, merge)
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.
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
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.