5

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.
Kira Nofans
  • 176
  • 1
  • 6
  • 20
  • Might help to post a screenshot of the command you're running along with the error it's returning. – rst-2cv May 26 '18 at 01:32
  • Thanks for the reply. I was following a simple tutorial using Android studio to initialize and then commit the files, and it failed several times due to AS's terminal, LF CRLF, and Untracked files. So I moved to git-shell. I'm now like ok where I should really start for using Git? – Kira Nofans May 26 '18 at 01:44
  • Please add the error log when pushing – muecas May 26 '18 at 01:53
  • I'm completely new to Git so may I know how to see the pushing error logs? – Kira Nofans May 26 '18 at 02:05
  • Post the entire output of the command that gives you the error you made this question for: `Push to origin/master was rejected` – rst-2cv May 26 '18 at 02:07

5 Answers5

10

You will try to send the command

git push -f origin master
dazn311
  • 123
  • 1
  • 4
3

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.

Jerinaw
  • 5,260
  • 7
  • 41
  • 54
  • Thanks for the reply. I was following a simple tutorial using Android studio to initialize and then commit the files. And it failed several times due to AS's terminal, LF CRLF, and Untracked files. So I moved to git-shell. I'm now like ok where I should really start for using Git? Plus I'm using Windows 10 – Kira Nofans May 26 '18 at 01:49
  • my master branch is in check out state now...I don't know how to reset this cause the shell system mentioned that one of the reason I can't push the file to the server is that the master branch is checked out – Kira Nofans May 26 '18 at 02:09
  • Where did you check it out from? – Jerinaw May 26 '18 at 02:11
  • Git-Shell. I tried to push the files with git-shell. and The errors in the block was from Android Studio when I tried to push – Kira Nofans May 26 '18 at 02:19
1

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.

rst-2cv
  • 1,130
  • 1
  • 15
  • 31
  • hum...I tried to pull with git-shell and it kinda worked, but after that when I tried to push the file to the server (also on git-shell), it said rejected, the same response as AS gave me – Kira Nofans May 26 '18 at 02:26
  • @KiraNofans When you say it kind of worked, what was the output of `git pull`? – rst-2cv May 26 '18 at 02:29
  • https://media.discordapp.net/attachments/442625661220159488/449734849683652610/unknown.png?width=768&height=198 this is the screenshot – Kira Nofans May 26 '18 at 02:33
  • @KiraNofans why did you use `--allowed-unrelated-histories`? – rst-2cv May 26 '18 at 02:34
  • That is because the system told me the pull was refused because of unrelated histories. – Kira Nofans May 26 '18 at 02:38
  • 3
    @KiraNofans if you don't care about losing a tiny bit of history, `git push --force` should work. – rst-2cv May 26 '18 at 02:47
1

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.

Rubén Viguera
  • 3,277
  • 1
  • 17
  • 31
0

This usually happens when I push my repository to GitHub and then use GitHub pages to publish my work, then later on when I make some tweaks in my local machine and try to push these changes it is rejected with the error message that the remote repo contains files that are not present in my local repo so I should try doing a git pull first, basically because after publishing to GitHub pages some _config.yml files are added to our repository which is not present in our local machine.

This can be solved using a git pull <remote fetch url> first which will download the _config.yml file on our local machine and then we can push using the git push command.

I am answering this here since this question was the first google search result when I tried searching for why my git push command won't work, although the problem in push is due to a different reason in this case, others might face my issue so I added this answer here.

KUMAR HARSH
  • 95
  • 1
  • 10