0

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
user3132457
  • 789
  • 2
  • 11
  • 29

1 Answers1

1

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • i already found the answer here: https://stackoverflow.com/questions/3601911/how-do-i-undo-a-checkout-in-git. all i had to do was ```git checkout -```! i don't know how ```git checkout master``` would help cause now it say ```Already on 'master'``` – user3132457 Mar 10 '18 at 06:49
  • @user3132457 If you did `git checkout origin/master` then you certainly were _not_ on `master`. Basically, it sounds like you don't understand Git. – Tim Biegeleisen Mar 10 '18 at 10:45
  • if i understood it well, i wouldn't do ```git checkout origin/master``` at first place. in question post i wrote all the commands i've done. so on which branch were i (based on that)? – user3132457 Mar 10 '18 at 12:19
  • As I mentioned, `origin/master` is a tracking branch, and yes you probably didn't want to checkout this branch. My answer gets you back to the right branch. – Tim Biegeleisen Mar 10 '18 at 14:05