Skip to content

Instantly share code, notes, and snippets.

@ddeveloperr
Last active September 6, 2023 15:52
Show Gist options
  • Select an option

  • Save ddeveloperr/97e7866b3da8042f1ea6324d337a1836 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

Nyce, was useful to me.

@arhoy

arhoy commented Dec 10, 2018

Copy link
Copy Markdown

Super! Thank you kindly

@SwedhaBalasubramanian

Copy link
Copy Markdown

works for me. Thank you

@bigOconstant

Copy link
Copy Markdown

Thanks, I always forget this

@ericksa

ericksa commented Sep 5, 2019

Copy link
Copy Markdown

Google goes right here :)

@lifeeric

Copy link
Copy Markdown

It did save my work!

@ddeveloperr

ddeveloperr commented Dec 19, 2019 via email

Copy link
Copy Markdown
Author

@aheze

aheze commented Nov 6, 2020

Copy link
Copy Markdown

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

@BlackGlassSkin

Copy link
Copy Markdown

thanks

@cgsdesign

Copy link
Copy Markdown

Thank you. Always useful just in case.

@Ndinyo

Ndinyo commented Jun 8, 2021

Copy link
Copy Markdown

Thank you, really needed this.

@ddeveloperr

Copy link
Copy Markdown
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
Copy Markdown

Easy and smooth... Thanks

@Er-shams

Er-shams commented Sep 2, 2022

Copy link
Copy Markdown

thanks

@englit2008

Copy link
Copy Markdown

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

@lifeeric

lifeeric commented Sep 15, 2022

Copy link
Copy Markdown

[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