Ad

How To Recover All Deleted Local Files Which Were Deleted Using Command (Git Checkout ...)?

- 1 answer

I had a project which I wanted to push to Git. So I create a local repo (git init). I had a .gitignore in remote repo so I couldn't push my local files to remote. So I did git checkout origin/master, and all my local files are gone.

Is there any way to recover them?

Here's what I have done:

git init
git add .
git commit -m "Initial commit"
git push origin master (failed)
git checkout origin/master
Ad

Answer

Assuming your git commit -m "Initial commit" step actually completed successfully, then your local master should have all your work. You may switch to that branch to verify this:

git checkout master

I don't know why you thought to checkout origin/master. This is the remote tracking branch, and it doesn't really have anything to do with your current problem. You need to resolve the reason why your pushes are being rejected.

Ad
source: stackoverflow.com
Ad