• Register
0 votes
1.4k views

Problem :

I am a beginner to Git . If I do the git push for the first time then it works fine for me and creates the remote branch also. But if I try to push for the second time for some eleventh hour updates then I get the below error:

Error: failed to push some refs to 'https://github.limeade.info/Limeade/product.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 am struggling with this error from past couple of days. Can somebody guide me in fixing it?

8 4 2
2,300 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

This issue happened to me very recently. I will guide you through the solution.

I just made the pull request to our master yesterday the way I usually do it.

One of my colleagues was just reviewing my work on it today and he saw that it was out of the sync with the master branch so with clear purpose of just helping me he simply merged my master against the branch on which I was working.

And he forgot to tell me that.

Then when I tried to merge master locally and I tried to push it, but it failed and gave the error which you are facing.. The reason was my colleagues merged with the master created one extra commit which I did not had locally.

So the very simple solution on it is Pull down the own branch so that I can have the extra commit. Then just push it back to the remote branch.

So I literally did below steps on my branch :

git pull

git push

5 2 1
4,980 points
0 votes

Solution:

The -f is actually required because of the rebase. Whenever you do a rebase you would need to do a force push because the remote branch cannot be fast-forwarded to your commit. You'd always want to make sure that you do a pull before pushing, but if you don't like to force push to master or dev for that matter, you can create a new branch to push to and then merge or make a PR.

Ensure that your local branch FixForBug is not ahead of the remote branch FixForBug pull and merge the changes before pushing.

git pull origin FixForBug
git push origin FixForBug

 

In case you want to avoid having to use -f, then you can use just

git pull

Instead of

git pull --rebase

 

The non-rebase will fetch the changes from origin/dev and merge them into your FixForBug branch. Then, you will be able to run

git push origin FixForBug

without using -f.

Let's assume the upstream branch is the one that you forked from and origin is your repo and you want to send an MR/PR to the upstream branch.

You already have let's say about 4 commits and you are getting Updates were rejected because the tip of your current branch is behind.

Here is what I did

First, squash all your 4 commits

git rebase -i HEAD~4

You'll get a list of commits with pick written on them. (opened in an editor)

pick fda59df commit 1
pick x536897 commit 2
pick c01a668 commit 3
pick c011a77 commit 4

To

pick fda59df commit 1
squash x536897 commit 2
squash c01a668 commit 3
squash c011a77 commit 4

After that, you can save your combined commit

Following this

You'll need to stash your commit

git reset --soft HEAD~1
git stash

 

now rebase with your upstream branch

git fetch upstream beta && git rebase upstream/beta

 

Now pop your stashed commit

git stash pop

 

Another way of solution

Let's assume the upstream branch is the one that you forked from and origin is your repo and you want to send an MR/PR to the upstream branch.

You already have let's say about 4 commits and you are getting Updates were rejected because the tip of your current branch is behind.

Here is what I did

First, squash all your 4 commits

git rebase -i HEAD~4

You'll get a list of commits with pick written on them. (opened in an editor)

example

pick fda59df commit 1
pick x536897 commit 2
pick c01a668 commit 3
pick c011a77 commit 4

to

pick fda59df commit 1
squash x536897 commit 2
squash c01a668 commit 3
squash c011a77 commit 4

After that, you can save your combined commit

Next Move

You'll need to stash your commit

Here's how

git reset --soft HEAD~1
git stash

now rebase with your upstream branch

git fetch upstream beta && git rebase upstream/beta

Now pop your stashed commit

git stash pop

commit these changes and push them

git add -A
git commit -m "[foo] - foobar commit"
git push origin fix/#123 -f

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 3 views
3 views
Problem: Hi! Can some one help me with this issue? pushed branch tip is behind its remote
asked Mar 19 PkGuy 13.1k points
1 vote
1 answer 6 views
6 views
Problem: How can I deal with this problem : updates were rejected because the tip
asked Mar 15 MUHAMMAD MUNEEB 80k points
1 vote
1 answer 11 views
11 views
Problem: I need a help , How I can fix this : updates were rejected because the remote contains work
asked Mar 15 MUHAMMAD MUNEEB 80k points
1 vote
1 answer 6 views
6 views
Problem: Any ideas on what I need to do to fix this? updates were rejected because the remote contains work that you do
asked Mar 15 MUHAMMAD MUNEEB 80k points
0 votes
1 answer 25 views
25 views
Problem : Error “push master to origin/master was rejected by remote”
asked Feb 23 Shovo210 13.2k points
0 votes
1 answer 209 views
209 views
Problem: I have fundamental knowledge on Git. I learned Git by watching online video tutorials. I am working on the rails 3.2 and I often receive below error if I try to push to the heroku: git push heroku master Counting objects: 496, done. Delta compression using up ... then deleting and again adding the remote but it is not working for me. I need help from git expert to fix above git error.
asked Jun 17, 2020 Raphael Pacheco 4.9k points
1 vote
2 answers 3 views
3 views
Problem: Getting errro while using GIThub. To push the current branch and set the remote as upstream, use.
asked Mar 30 PkGuy 13.1k points
0 votes
1 answer 1.2K views
1.2K views
Problem: I am having only basic knowledge of git. Now I am trying to clone the project from a gitlab to my own local machine. I have already been granted rights as the developer on it and I have used the command as 'git clone’. But none of the ... “Remote: The project you were looking for could not be found.” Any help in fixing my git related error would be highly appreciated.
asked Sep 4, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 9 views
9 views
Problem: There is no tracking information for the current branch
asked Mar 19 ummesalma 21.9k points
0 votes
1 answer 22 views
22 views
Problem : Your branch is based on 'origin/master', but the upstream is gone.
asked Feb 26 Shovo210 13.2k points