Getting error when trying to git push to remote branch (Heroku) - heroku

Hi I tried to push my local changes to heroku production but I am getting the following error
Zhens-MacBook-Pro:Dailymuses-Server-Side zaikshev88$ git push heroku-production master:master
To git#heroku.com:dailymuses.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#heroku.com:dailymuses.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.
The issue here is that when I tried to do a git pull, I was told that everything is up to date
Zhens-MacBook-Pro:Dailymuses-Server-Side zaikshev88$ git pull origin master
From github.com:mingyeow/Dailymuses-Server-Side
* branch master -> FETCH_HEAD
Already up-to-date.
What is the issue here and how can I resolve it?

Your push command is to remote heroku-production but your pull command is to origin. The non-fast-foward message means the history in your current repo differs from the Heroku remote; likely someone has pushed a branch with some merges or rebases.
I implore you to not use Heroku as the authoritative git remote. Assuming you are not, you can force push over the Heroku master branch to resolve this.
git push -f heroku-production master:master

Related

BitBucket - error: failed to push some refs

I have some projects I would like to upload on my bitbucket private profile. I performed the following steps but I get an error.
Convert my project to git with: git init
Next:
git add
git commit -m "some message"
I created a bitbucket repository and version control system is GIT.
I then type this (of course with real account name and reponame and repo owner):
git remote add origin https://<repo_owner>#bitbucket.org/<accountname>/<reponame>.git
Finally,
git push -u origin master
I did all of this and my terminal gives me this error:
To https://bitbucket.org/milosdev_me/lfs.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://milosdev_me#bitbucket.org/milosdev_me/lfs.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Try:
git push origin master --force
This works for me.
Your master branch has some code that you don't locally have, and to prevent you from conflicts, it doesn't let you to push further changes, before you have them locally. To resolve this, pull all the changes to your local repository (your project):
git pull origin master --allow-unrelated-histories
After that, you will have all the code that is available on your master branch.
NOTE: Be careful, pulling the code from remote branch might mess up all the changes locally. Make sure to save those changes somewhere, or create another branch locally where you will pull your origin master branch, so it doesn't mess up your changes.
Your issue is that you have different things between your local repository and your git repository (probably a readme file that you created automatically), so you have two options:
use git pull origin master, with this command, you will pull from your git repository, but it will cause a merge conflict, which you have to resolve using an IDE (recommended to beginners) or through cmd.
use git push origin master --force, this way, you will force your push from your local repository to your git repository, ignoring any merge conflict by overwriting data. I'm not sure, but I think it will overwrite all git repository data with you local repository data (which is what you want).
Adding --force option is a bad idea
Either rebase it or pull the code, merge it and push it.
git pull --rebase origin master
git push -u origin master
Your remote repository and local repository have differences, something new in remote repository. So for pushing you need pull changes, from remote, previously. Try do:
git pull
git push -u origin master
The issue is because your remote repository and local repository have differences.I had same issue and i tried all the above mentioned solution but nothing worked for me.
For me the scenario was :- I already had my branch in remote repository.If you have the same scenario then follow below steps:-
run command 'git pull'
delete branch from local repository
checkout that particular branch using "checkout as a new local branch" from
the Remote repository.
run command 'git branch -u <your_branch_name>'
run command 'git push or git push --force'
or you can try directly from step 4 first , if it does not work then follow entire steps.Hopefully it will help someone.
If you have your bitbucket account linked to jira.
(this answer will work for you, only if you have your jira account linked to bitbucket)
I was having the same problem trying to push my current branch with the origin.
for example:
my branch name was:
feature/PREFIX-000-new-name-branch.
previous commit:
git commit -m "Write your commit here"
so far it was not working.
you have to mentioned the ticket name in the commit.
if you have made the commit, make an --amend to rename your commit and retry it.
git commit --amend -m "PREFIX-000 Write your commit here"
try the push again.
If you are using BitBucket, this issue occured when I tried to push to a branch but that branch has writing disabled via the repository settings.
if you have already created a project locally and you want to upload it to git,
you will then need to do:
git status to see the changes you need to upload
git add . to add those changes to your repo
git commit -m "" to add a commit message
git push origin master
that way I solved the very same problem I
was having.
it might be a configuration issue
I fixed this issue after updating the global user.email value with my email
git config --global user.email my#email.com
Note: You need to delete the previous commit because it had the wrong email in the commit

Unable to Git push to a remote branch (not master) from azure pipeline

I have been trying to do a Git Push from a bash task on Azure DevOps. I was already pushing the code to the master branch without any issues.
But now I have to push it to the dev branch, and for some reason, Git Pull works but not Git Push. These are the steps I followed. I tried various versions of this actually, but nothing worked.
git config --global user.email "xxx#gmail.com"
git config --global user.name "abc"
git pull https://PAT#github.com/repo.git HEAD:dev
git add $PROXYNAME
git commit -m 'Auto-checkin of $PROXYNAME proxy to Git'
git show-ref
git push https://PAT#github.com/repo.git HEAD:dev
The above worked when the push / pull had HEAD:master at the end.
This is the error I have been getting each time.
To https://github.com/repo.git
! [rejected] HEAD -> dev (non-fast-forward)
error: failed to push some refs to 'https://***#github.com/repo.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Edited to add:
I have also tried with a checkout command - to checkout that dev branch, and no luck!
Result of git remote -v:
origin https://github.com/repo (fetch)
origin https://github.com/repo (push)
The latest error am getting is below:
error: src refspec dev does not match any
error: failed to push some refs to 'https://***#github.com/repo.git'
Could anyone please let me know what I need to do to get this working. This seems to be a recurring issue for me now :(
I believe you need to configure git remote to your correct repository.
The result of git remote -v should refer to your current directory remote association.
Start with git remote --help
Especially:
git remote set-url [--push] [] git remote
set-url --add [--push]
Here is a good tutorial on git remote.

Heroku+BItbucket deploy: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart

I am now working on a website. I use heroku to run my server and use bitbucket as the version control tool. I setup a pipeline to deploy directly from bitbucket to heroku. But I keep getting an error like:
+ git push https://heroku:$HEROKU_API_KEY#git.heroku.com/$HEROKU_APP_NAME.git HEAD
To https://heroku:57eb7889-7395-4a7e-bd95-1312a40b30d1#git.heroku.com/hidden-ocean-90048.git
! [rejected] HEAD -> master (non-fast-forward)
error: failed to push some refs to 'https://heroku:57eb7889-7395-4a7e-bd95-1312a40b30d1#git.heroku.com/hidden-ocean-90048.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 tried git pull and git pull -f but it doesn't work. Please help me.
You can push with -f like the below:
git push -f https://heroku:$HEROKU_API_KEY#git.heroku.com/$HEROKU_APP_NAME.git HEAD

Octopress pushing error to GitHub

I'm trying to push an octopress to github page,everything has worked fine up to now but when i do the rake deploy command after displaying octopress files i get the following error
To git#github.com:rukshn/rukshn.github.io.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:rukshn/rukshn.github.io.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.
what's the problem?
Since this is the master branch, i.e., the one running your generated pages, you need to drop into the _deploy directory, then do the git pull origin master. Somehow your deploy directory has gotten out of sync. Do you have more than one local repo you write to and deploy from? (Say on different machines...) If you do, then you should always make sure to sync your the sources on the various repos as well.
do
cd _deploy
git reset --hard origin/master
cd ..
and try again
rake generate
rake deploy
Try:
git checkout source
rake gen_deploy
#slavik comment works like a charm.
#Benjamin I think #rksh skipped below steps,
Don't forget to commit the source for your blog.
git add .
git commit -m 'add source code to source branch'
git push origin source
I met the problem and solved it by removing the master branch in the _deploy folder in the source branch. The detailed commands are as follows:
// change directory to _deploy
cd _deploy
// check out local master branch
git checkout master
// rename local master to master2
git branch -m master2
// list of remote branch
git branch -r
// create a new local master branch and tracking remote master branch
git checkout origin/master -b master
// pull the remote master branch, ensure that the local master branch has Already up-to-date.
git pull
// delete the local master2 branch if not needed.
git branch -d master2
```

How to push to new git branch not with Xcode

I've been using a git branch with a remote repo as well (Bit bucket)
I decided to create a new branch so ran this code
Directory= ~/tmp/merge/aaa> git branch iOSUI/beta
Directory= ~/tmp/merge/aaa> git checkout iOSUI/beta
Switched to branch 'iOSUI/beta'
Then tried to push
Directory= ~/tmp/merge/aaa> git push origin iOS7UI/beta
error: src refspec iOS7UI/beta does not match any.
error: failed to push some refs to 'https://xxx/repo.git'
So I tried to create a remote branch
Directory= ~/tmp/merge/aaa> git branch origin iOSUI/beta
error: there are still refs under 'refs/heads/origin'
fatal: Failed to lock ref for update: Is a directory
After that failed I tried through XCode by selecting push and then it pushed successfully to
'origin/iOS7UI/beta'
Again I tried through the command line 2 options
Directory= ~/tmp/merge/aaa> git push origin iOS7UI/beta
error: src refspec iOS7UI/beta does not match any.
error: failed to push some refs to 'https://xxx/repo.git'
and this option with the '/'
Directory= ~/tmp/merge/pixtr> git push origin/iOS7UI/beta
fatal: 'origin/iOS7UI/beta' does not appear to be a git repository
fatal: Could not read from remote repository.
The recent default push policy "simple" would prevent you to push to a non-existent branch (unless it is set to be your upstream branch).
You would need to do:
git push -u origin iOS7UI/beta
But check first if the branch from which you have created your iOS7UI/beta is pushed or up-to-date compared to the upstream repo.
If it is behind, that means iOS7UI/beta is based on a parent SHA1 which isn't yet pushed to origin.

Resources