1 min read

How to reset a Git branch to a remote branch

How to reset a Git branch to a remote branch

Sometimes we meet testing changes on your local branch and need to immediately reset to the remote branch.

We can solve this problem follow three ways.

Creating a branch and committing changes to have a backup

git commit -a -m "my mess"
git branch my-mess

Stashing changes for future use

git stash push -u -m "my stash" 

Resetting the branch and discarding the changes

If you want to reset and stay in master state, use the code below.

git fetch origin
git reset --hard origin/master

You can reset to any branch by changing the name master to your preferred branch.

Quick and easy, how it should be. That's all for now.