Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I always Got Error "Push to origin/master was rejected"?

EDIT: one of the things should be aware of if you are using git bash is that BETTER TO KEEP AUTOCRLF FALSE

git config --global core.autocrlf false

========================================================

I'm new to git and I got problems deploying files...

I just pulled files successfully (?) using commands, and now I'm trying to push...

Commit Logs below: (I have several reverts because I have failed to commit several times due to LF, CRLF, or untracked Files errors)

And in AS I got "Push to origin/master was rejected"

The Error when pushing

hint: Updates were rejected because the tip of your current branch is behind
!   refs/heads/master:refs/heads/master [rejected] (non-fast-forward)
Done
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.
18:53:20.176: [Lab1_movie] git -c core.quotepath=false -c 
log.showSignature=false pull --progress --no-stat -v --progress origin 
master
From https://github.com/kiranofans/Lab1_MovieApp
 * branch            master     -> FETCH_HEAD
 = [up to date]      master     -> origin/master
fatal: refusing to merge unrelated histories
18:57:26.215: [Lab1_movie] git -c core.quotepath=false -c 
log.showSignature=false push --progress --porcelain origin 
refs/heads/master:master
github --credentials get: github: command not found
github --credentials store: github: command not found
error: failed to push some refs to 
'https://github.com/kiranofans/Lab1_MovieApp.git'
To https://github.com/kiranofans/Lab1_MovieApp.git
!   refs/heads/master:refs/heads/master [rejected] (non-fast-forward)
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
Done
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
like image 979
Kira Nofans Avatar asked May 26 '18 01:05

Kira Nofans


People also ask

Why is git push origin master not working?

If git push origin master not working , all you need to do is edit that file with your favourite editor and change the URL = setting to your new location. Assuming the new repository is correctly set up and you have your URL right, you'll easily be able to push and pull to and from your new remote location.

How do I fix push rejection?

If you get a failed to push some refs to error, the main thing to do is git pull to bring your local repo up to date with the remote. Avoid employing the --force flag when using git pull and prevent other developers' accidental overwrites of committed features.

What does push origin master mean?

With git push origin master you tell git to push all of the commits in the currently checked out local branch (i.e. from your file system) to the remote repo identified by the name origin on its remote branch named master .


Video Answer


4 Answers

You will try to send the command

git push -f origin master
like image 130
dazn311 Avatar answered Oct 18 '22 18:10

dazn311


I'm not sure what exactly you're asking here. And those logs are not very helpful.

But since you're asking about pushing...

Generally you've started out by cloning a repo or you've run git init and created one.

You then edit or create files in that repo.

You then need to stage those file to be committed.

git add <file1> <file2> ...

You can see what's been staged with git status

If everything looks good you can commit those changes

git commit -m "My commit message"

If you've cloned a remote repository, and you have permissions to push to it

git push <remote> <branch> so something like git push origin master

You can view your remotes with git remote -v

You can add a remote if you don't see the remote you need in the list git remote add <give it a name> <the URL to the repo> so something like git remote add upstream https://github.com/me/myrepo.git

And then push to it git push upstream master

Git for Windows: https://git-scm.com/download/win
The reference manual: https://git-scm.com/doc
Here's a how to: https://githowto.com/

[Update]
Those logs are better. Line 5 is telling you what you need to do. git pull
Some one must have pushed changes before you did. So you need to pull those changes into your repo. fix any conflicts, commit, and push.

like image 35
Jerinaw Avatar answered Oct 18 '22 19:10

Jerinaw


If you read the error message, it says:

hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.

Pay attention to that second line.

Try to do a git pull, and then try and git push again. It should work.

like image 1
rst-2cv Avatar answered Oct 18 '22 18:10

rst-2cv


I had the same error when trying to push to an existing repository for a first time with my user.

My problem was my user had general WRITE permissions to repository but not to branches. So if also it is your first time pushing, just check your permissions.

like image 1
Rubén Viguera Avatar answered Oct 18 '22 17:10

Rubén Viguera