DEV Community

Cover image for GIT Command - Overwrite Trick
André Hatlo-Johansen
André Hatlo-Johansen

Posted on

3 2

GIT Command - Overwrite Trick

A short post to all those who have difficulty with repository hell. This Git command parts the sea, brings peace and makes the local repository die for your sins.

Especially in IntelliJ i was faced with this issue numerous times, not being able to switch branches without going through some kind of satanic IntelliJ ritual of saving the repo changes to a shelf.

The solution is here:

Force overwrite of local files from remote repository:

$ git fetch --all
$ git reset --hard origin/master
Enter fullscreen mode Exit fullscreen mode

To download changes from some other branch

Use the following command:

$ git reset --hard origin/<insert_other_branch>
Enter fullscreen mode Exit fullscreen mode

Git fetch downloads latest updates from remote, but doesn't merge or rebase in local files.

Thank the lord! The repo is resurrected back to its stable form!

Want to know more, check out the Git cheat sheet here!

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay