GIT Command - Overwrite Trick

andrehatlo

André Hatlo-Johansen

Posted on March 28, 2022

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!

💖 💪 🙅 🚩
andrehatlo
André Hatlo-Johansen

Posted on March 28, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related