Skip to content

Instantly share code, notes, and snippets.

@ddeveloperr
Last active September 6, 2023 15:52
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ddeveloperr/97e7866b3da8042f1ea6324d337a1836 to your computer and use it in GitHub Desktop.
Save ddeveloperr/97e7866b3da8042f1ea6324d337a1836 to your computer and use it in GitHub Desktop.
How to force “git push” to overwrite remote repo files WITH LOCAL files

You want to push your local files to remote files

git push -f <remote> <branch>
git push -f origin master

Local version has priority over the remote one!

more...

@realJema
Copy link

Nyce, was useful to me.

@arhoy
Copy link

arhoy commented Dec 10, 2018

Super! Thank you kindly

@SwedhaBalasubramanian
Copy link

works for me. Thank you

@bigOconstant
Copy link

Thanks, I always forget this

@ericksa
Copy link

ericksa commented Sep 5, 2019

Google goes right here :)

@lifeeric
Copy link

It did save my work!

@ddeveloperr
Copy link
Author

ddeveloperr commented Dec 19, 2019 via email

@aheze
Copy link

aheze commented Nov 6, 2020

Nice, worked great! Example: git push -f https://github.com/aheze/YourRepo main

@BlackGlassSkin
Copy link

thanks

@cgsdesign
Copy link

Thank you. Always useful just in case.

@Ndinyo
Copy link

Ndinyo commented Jun 8, 2021

Thank you, really needed this.

@ddeveloperr
Copy link
Author

I really appreciate it. :) Stay connected here on GH .... I've just back to your profile and follow you and will learning something for sure
@Ndinyo @cgsdesign @BlackGlassSkin @aheze @lifeeric @ericksa @bigOconstant @SwedhaBalasubramanian @arhoy @realJema

"Instead of better glasses, your network gives you better eyes." -- Ronald Burt

Regards,
Kemal

@gasiferox
Copy link

Easy and smooth... Thanks

@Er-shams
Copy link

Er-shams commented Sep 2, 2022

thanks

@englit2008
Copy link

Thank you. It's works for me also. Good Job!

@lifeeric
Copy link

lifeeric commented Sep 15, 2022

[Hack] easy way is to change url directly from the source code,
open .git/config file in your favorite editor or nano , vim.

$ nano .git/config

and change the url = git@github.com:lifeeric/uploadToS3.git your repo url:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = git@github.com:lifeeric/uploadToS3.git     # here paste your url
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
        remote = origin
        merge = refs/heads/main
[pull]
        rebase = false

Hope you like it. thank you!

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