deleted by mistake all the files of my repository

hey I made a mistake I ran these commands then my projects become empty. Is there a way I can restore it it’s very very very important project I have been working on it for months?
rm -rf .git
git init
git add.
git commit -m “Initial commit”
git remote add origin git@github.com:/.git
git push -u --force origin master

Hey and welcome @maroine888 ! Let’s see if we can get this fixed for you.

This is a tricky situation, as you can’t for example use the Git reflog - you’ve deleted your entire Git repository locally, then pushed an empty repository to master.

Do you have any branches pushed to GitHub that you can use to recover? A branch will typically also contain all previous commits, so that you don’t lose everything. If not, do you have a backup of your local working directory you can revert back to? You can force-push the backup version of your master branch again.

And I know these words may arrive too late, but next time, please make sure to:

  • Back up local files and folders at a regular interval
  • In general, try avoiding force-pushing to master
  • Never run commands on your machine if you don’t understand what they do