Reset local git repository to same like remote

Pritesh Gohil
1 min readMay 11, 2020

Sometime we mess-up with local git branch and we need to ignore all the local changes in files and folder. At the same time, you would like to match your local repository to the remote branch. All this can be done only with three commands,

First, get latest changes from the remote

git fetch origin

Second, hard reset the branch.

git reset --hard origin/master

Last step is to remove all the untracked files (-f) and directories (-d), plus ignored files (-x).

git clean -d -f -x

Helps in saving lot of time instead of deleting and re-cloning remote repository.

--

--