I am trying to reproduce a problem that resulted from my attempted answer to this question.
In short
A github user tried to do git pul
I can't comment due to low repo, but I installed wordpress this morning and did exactly this.
git init
git add .
git commit -m "initial commit"
at this point, I had realized I already created the github page for it, WITH a default readme in it.
So, not knowing this would be an issue, I tried to push as
git remote add origin http://github.com/user/repo.git
git push -u origin master
This is when I received the message:
$ git push -u origin master
To https://github.com/user/project.com
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/user/project.com'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
So, instead of force pushing and erasing that README file on github, I did git pull --rebase
and git showed me this message
First, rewinding head to replay your work on top of it...
I waited about 5 minutes, before I ctrl+C
out of the process, and realized there were about 8-9 files removed from the wordpress site. git status
also showed me the removed files.
I was able to recover those files using git reflog
which showed me my first commit on HEAD@1 and I recovered my files with git reset --hard "HEAD@{5}"
git pull
will delete ever tracked file on another path.
refer to Why git rm --cached not remove local ever tracked file but others