2

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

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

error: failed to push some refs to 'ssh://website@host.website.com:2200/home/user'

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):

core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
receive.denycurrentbranch=updateInstead

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 .git. 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)

Addendum

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://website@host.website.com:2200/home/user
 ! [remote rejected] master -> master (Could not update working tree to new HEAD)
error: failed to push some refs to 'ssh://website@host.website.com:2200/home/'

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)

Community
  • 1
  • 1
BeetleJuice
  • 39,516
  • 19
  • 105
  • 165

1 Answers1

1

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • omg, I started running your first command -- It's running as we speak -- and then realized that you've been making edit after edit. lol – BeetleJuice Sep 11 '16 at 10:18
  • Even `--force` didn't work although it was a lot busier than my original command. I've updated the OP with the results. – BeetleJuice Sep 11 '16 at 10:25
  • @BeetleJuice No biggie: the remote repo has still its old history of commits in the reflog: nothing get lost. – VonC Sep 11 '16 at 10:25
  • @BeetleJuice As for your error message, you should if possible push to a clean working tree (one without any modified or untracked files). If not possible, at least remove the untracked files which would be overwritten by your push. – VonC Sep 11 '16 at 10:26
  • Sorry not familiar with `Git` lingo yet. When you say *"at least remove the untracked"*, you mean `git clean -f`? – BeetleJuice Sep 11 '16 at 10:31
  • @BeetleJuice yes, or git reset --hard, but you mentioned " there are files in there that are not part of my project, but that I don't want to move": so make sure you don't erase too much. That is why I would start by just removing manually the sole problematic file, before trying more radical approaches. – VonC Sep 11 '16 at 10:33