-1

Locally I have files, which i need to push to gitlab repository. But gitlab repository already has some files. But i need to rewrite them by files from my local. When i try

git push --set-upstream origin master

i get

error: failed to push some refs to 'http://gitlab2.fbn/analytics/airflow.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally.

What should i do to rewrite everything in gitlab?

Vlad Aleshin
  • 361
  • 4
  • 15
  • your remote has more updated files that your local. By force pushing you will rewrite that work (possibly destroying someone else's work). Please take your time to read a basic git guide – Daemon Painter Dec 01 '20 at 09:10
  • 1
    Does this answer your question? [Force "git push" to overwrite remote files](https://stackoverflow.com/questions/10510462/force-git-push-to-overwrite-remote-files) – Daemon Painter Dec 01 '20 at 09:12
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+remote+contains+work+that+you+do – phd Dec 01 '20 at 11:43

2 Answers2

1

You can use --force or -f. This will rewrite the remote and push everything from local.

git push origin master --force

or

git push origin master -f # one dash before f

Refer here for more about git force push.

Hoto Cocoa
  • 489
  • 3
  • 12
theWellHopeErr
  • 1,856
  • 7
  • 22
  • 2
    Please be aware: force pushing is an operation that even the more skilled in git try to avoid because it makes more harm than good. This answer will solve your problem, but doesn't warn you about the caveats of doing so. – Daemon Painter Dec 01 '20 at 09:12
1

Don't use force-push. I recommend pull repository before push. Then git will ask to you about conflict.

Hoto Cocoa
  • 489
  • 3
  • 12