Reset
You can reset the commit for a local branches using git reset
To change the commit of a local branch:
git fetch
git reset --hard "@{upstream}"
On Windows or with PowerShell, specify "@{u}" (with double quotes).
git fetch
git reset --hard @{upstream}
The advantage of specifying @{u}
or its verbose form @{upstream}
is that the name of the remote repo and branch don't have to be explicitly specified.
Be careful though, as the docs put it:
Resets the index and working tree. Any changes to tracked files in the working tree since are discarded. If you want to actually keep whatever changes you've got locally - do a
--soft
reset instead. which will update the commit history for the branch, but not change any files in the working directory (and you can then commit them).
Clean
Erasing your project directory and re-cloning from the remote, to remove even files that are in your .gitignore
, use git clean
to remove untracked files, optionally also with -x
:
git clean -df
Warning: git clean -xdf
is irreversible and you may lose files and data (e.g. things you have ignored using .gitignore
).