• Register
0 votes
1.2k 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 103 views
103 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
0 votes
1 answer 436 views
436 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 31 views
31 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, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 54 views
54 views
Problem : I am unable to clone my Git repository and getting below error: ​/c/Projects $ git clone http://stage.abc.com:10088/pqr http://<url>/<repository> Cloning into '<repository>'... fatal: could not read Username for 'http://<url>': No such file or directory ​ How can I fix the above error?
asked Jan 16, 2020 jwilliam 3.9k points
1 vote
1 answer 86 views
86 views
Problem : I am unable to clone my Git repository, and getting below error: /c/Projects $ git clone http://stage.abc.com:10088/pqr http://<url>/<repository> Cloning into '<repository>'... fatal: could not read Username for 'http://<url>': No such file or dir Please let me know any pointers to resolve my error.
asked Dec 30, 2019 alecxe 7.5k points
0 votes
2 answers 155 views
155 views
Problem : When ever I try to push to a shared git remote I get the following error remote: error: insufficient permission for adding an object to repository database ./objects
asked Nov 16, 2019 peterlaw 6.9k points
0 votes
2 answers 1.4K views
1.4K views
Problem : I am new to git. I am creating the new rails application but warning in git about LF replacement. I do git init git add . and then boom! I see this pop up for almost all files. I always face below warning usually if I build the application then it ... your working directory. warning: LF will be replaced by CRLF in README. I am unable to understand the message. How can I fix the message?
asked Feb 24, 2020 mphil 2.3k points
0 votes
1 answer 235 views
235 views
Problem : I have recently started using Git. I am still learning about Git. I tried to do the pull from the remote repository. But now I am facing below error message: "Please enter a commit message to explain why this merge is necessary, especially if it merges an ... nothing is really happening for me. How can I fix the above error message. I am currently learning to use terminal on the OS X.
asked Mar 3, 2020 mphil 2.3k points