As meagar said git rm
is a deletion recorded in a new commit, so it's recoverable and can be used without fear.
git reset --hard
can be especially harmful since it resets the "current commit" (HEAD
in Git jargon) to another one. So if the previous HEAD wasn't referred in a branch or a tag, it is virtually lost (at least without wizardry). It also causes your uncommitted changes to be lost.
The same goes for deleting branch and tag: it can cause a line of commits to be purged from the repository. In those cases, where commits are hidden in the repository, you can recover them but it's technical and not very easy, so you'd better know what you're doing.
As in any other situation where your data is precious (and source code is), it is highly desirable to have a mirror of your repository, and to regularly push to it. It can be another local repository, a private GitHub repo, or just the backup of your repository using your current backup system. This way you can always recover things.
As others say here, watch out for untracked file that are indeed important. Untracked/ignored files should be only the one that are generated from the files under version control: executables and such.
-f
, and triggering the garbage collection usinggit gc
. Everything else is completely recoverable in a timely manner.