• Register
0 votes
930 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

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 70 views
70 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 Raphael Pacheco 4.9k points
0 votes
1 answer 108 views
108 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 Raphael Pacheco 4.9k points
0 votes
1 answer 8 views
8 views
Problem: I have basic knowledge of GIT. Whenever I try to pull in my project directory in my terminal then I face the below error: /Sites/branch1$ git pull origin master U app/config/app.php U app/config/database.php U app/routes.php Pull is not possible because you have ... 'git commit -a'. Why does my git is showing me above error? and how can a beginner like me fix above git pull error?
asked Aug 27 Raphael Pacheco 4.9k points