BeetleJuice BeetleJuice - 1 year ago 90
Git Question

Learning Git: Remote rejects my push despite proper config?

I'm just learning

so please bear with me. I wrote some code locally and I would now like to push it to my remote server (
). I get this error:

! [rejected] master -> master (fetch first)

error: failed to push some refs to 'ssh://'

Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing

The remote is
v 2.4.1
and has this settings (output of
git config --list


Doesn't the last mean that I should be allowed to override conficts without raising an error?

I'm basically looking for the simplest setup: I don't develop on the server and I'm the only one with access to it, so I want whatever the dev machine pushes to win.

I saw this answer about making the remote repository bare, but the instructions were to delete everything in the folder but
. That doesn't work for me because there are files in there that are not part of my project, but that I don't want to move

If I log into the remote repository and execute
git status
I see

Untracked files: (use "git add ..." to include in what will be committed)

...(long list of files)

nothing added to commit but untracked files present (use "git add" to track)


I just did:

$ git push --force origin master
stdin: is not a tty
Counting objects: 3801, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3674/3674), done.
Writing objects: 100% (3801/3801), 6.95 MiB | 37.00 KiB/s, done.
Total 3801 (delta 2450), reused 0 (delta 0)
error: Untracked working tree file 'cacert.pem' would be overwritten by merge.
To ssh://
! [remote rejected] master -> master (Could not update working tree to new HEAD)
error: failed to push some refs to 'ssh://'

I'm thinking I can just delete the server's copy of that file and try again? The two files have the same content (it was a copy/paste job)

Answer Source

I don't want the local to import any change from the remote I want local files to overwrite remote files

The provblem is, with that error message, if you don't want to git pull, you need:

git push --force

But that will not just overwrite the files, it will overwrite the recent history of commits on the remote side by your commits, so make sure that is indeed what you want.

the remote has setting receive.denycurrentbranch=updateInstead. Doesn't that mean that my push should just update the remote master branch?

It allows to push to a non-bare repo (see more here about the "push-to-deploy"), but the error message is not about that.
It is about commits on the remote side that you don't have locally.

Normally, you pull --rebase, to replay your changes on top of the updated fetched remote branch. Then you push.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download