Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save mingderwang/94205de855af7c60cafa88564ea6abd7 to your computer and use it in GitHub Desktop.
Save mingderwang/94205de855af7c60cafa88564ea6abd7 to your computer and use it in GitHub Desktop.
hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git pull origin master //run this first, then
$ git push origin master
@koderka2020
Copy link

git push -f origin main

@Prajwal-Adhav
Copy link

Prajwal-Adhav commented May 26, 2021

git pull origin <branch-name> eg:- git pull origin <main>
git push origin <branch-name> eg:- git push origin <main>

This might work!!

@KeitoKat
Copy link

KeitoKat commented Jun 2, 2021

Amazing! Thank you so much :)

@sonali1512
Copy link

@Xenia-Io It worked. Thanks a ton.

@Aaryangarg8534
Copy link

Thanks this is really helpful for me

@sara-pourabbas
Copy link

Bro didn't work for me this solutions.Dont give trash info.You failed bro.So my friend Onur solved this problem.Don't do this againn maan.İf you don't know, don't sniff again.

try git push -f origin master

This works for me , Thank you.

@toppylawz
Copy link

Bro didn't work for me this solutions.Dont give trash info.You failed bro.So my friend Onur solved this problem.Don't do this againn maan.İf you don't know, don't sniff again.

try git push -f origin master

works amazingly.

@irepairny
Copy link

graet! git push -f main worked for me

@Md-Moniruzzaman
Copy link

Thanks this is really helpful for me

@Guta19
Copy link

Guta19 commented Mar 28, 2022

Thanks! git push -f origin master worked for me

@adityaharist
Copy link

git push -f origin master
Command above, it's so helpfully for anyone who in terminal says:

! [rejected] master -> master (fetch first)
error: failed to push some refs to '[your repo]'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

@saeidabdi
Copy link

Thanks! It worked
@Xenia-Io

@apaarsadhh
Copy link

I even had the same issue and i couldn't fix it with git pull but i tried this and it worked:
git push -f origin master
So try all previous steps but for git push use argument -f

It worked for me

You 're welcome !!!! But just be careful because with what i proposed "git push -f origin master" you update the whole repo and changes will be overridden from now on. So we should not do "git push -f origin master" every time - especially if you have contributors in your repo - you may need to do git reset then !!!

Thanks a lot 👍👍👍

@peternguyen173
Copy link

git push -f origin master

thank you it also worked for me too!

@Shubhamgupta0596
Copy link

thanks works for me as well

@asgharali101
Copy link

try git push -f origin master this worked..Thank u very much Xenia

it work for me ,,i am worried about it .thank you gentleman

@itihask56
Copy link

Yeah, it worked !!
Actually, my branch is main, so I had just changed the command: git push origin -f master, to command: git push origin -f main

@dipakshendge
Copy link

I even had the same issue and i couldn't fix it with git pull but i tried this and it worked:
git push -f origin master
So try all previous steps but for git push use argument -f

This worked great for me, thank you @Xenia-Io

thanks it's working...

@vinaykasam13
Copy link

Thank you so much, worked for me as well

@RadriaansNES
Copy link

Nothing was working from me. Copied previously local git files from folder into new folder and easily overwrote it.

@Shubham651-creator
Copy link

It's work very fine, thanks!

@Rakshitharashgithub
Copy link

hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

please check the above error I'm getting while push please check and let me know the solution

@Shubham651-creator
Copy link

I am just run only two commands.

  1. git pull origin
  2. git push origin

@GurwinderSethi
Copy link

Thank you so much for such a magnificent work

@ejazulhaq91
Copy link

great! git push -f main worked for me

@ashutoshlivnest
Copy link

git pull origin main
git add .
git commit -m "Merge remote changes"
git push origin main

@RonaldBeckstead
Copy link

I am having a problem, can I ask it here or start a new thread?

@thibapso
Copy link

thibapso commented Feb 6, 2024

Bro didn't work for me this solutions.Dont give trash info.You failed bro.So my friend Onur solved this problem.Don't do this againn maan.İf you don't know, don't sniff again.

try git push -f origin master

This worked for me. Thank you so much!

@LevarGoldun
Copy link

Thanks, it all worked. Most likely my error was due to the fact that I manually uploaded the file to github, but locally it wasn't showing up.

@spxctr00m
Copy link

I used git push -f origin main and it worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment