1

I have worked on my project for 3 days. When I finished the first function, I wanted to put files into a git repo. So, I used git init. and set up a remote repo. But I had to pull a readme file first. When the process is finished, everything in my local repo is gone. :(

My github repository has only a README file.

The command that I used are following:

  1. git init to my work repo
  2. git add *
  3. git remote add origin https://github.com/username/repositoryname.git
  4. git pull origin master

After that, I got the README file and all my local files are gone! Are there ways to get them back?

lvarayut
  • 13,963
  • 17
  • 63
  • 87
  • Did you commit the files before pulling the readme file? (in git you can always commit without pulling, you only can't push without it) – Jan Hudec Aug 07 '13 at 10:58
  • 1
    A git pull does not delete local files in the way you describe. Are you absolutely certain they are not still there in another directory, perhaps up a level? – naomi Aug 07 '13 at 11:10
  • I didn't commit anything. I just init my local repo. Then, I pull the readme file. I forgot it would merge my local repo and delete all my local files. – lvarayut Aug 07 '13 at 14:38
  • @JanHudec you actually ***can push*** in Git without having committed work in progress, however, you'd probably get errors if you had no commits to push at all (i.e empty repo with no commits). –  Aug 07 '13 at 15:10
  • 1
    @FrenchBulldog we're going to need way more information about ***what were the exact commands you used*** before we can reasonably help you. –  Aug 07 '13 at 15:12
  • @FrenchBulldog: Git never ever deletes files that were not added to it. Git also never merges when there are modifications of files that are known to it or when anything has been added and not committed. Can you write down the sequence, in specific commands, as closely as you remember it? (The shell history file might be of help) – Jan Hudec Aug 07 '13 at 15:16
  • 1
    See also [this comment](http://stackoverflow.com/questions/17771679/how-to-undo-a-git-rm-r-f#comment25923331_17773646) and [this answer](http://stackoverflow.com/questions/17771679/how-to-undo-a-git-rm-r-f/17773646#17773646), which may be applicable. –  Aug 07 '13 at 15:32
  • @Cupcake, Jan Hudec I have specified my question. – lvarayut Aug 07 '13 at 15:32
  • 1
    @FrenchBulldog I replicated the steps you have above, and I didn't get the same result. `git pull origin master` did not overwrite any of the untracked files I had in the folder after doing `git init`. Did you actually run `git add` after you ran `git init`? –  Aug 07 '13 at 15:35
  • @Cupcake I am sorry. I over one step. I ran command `git add *` after the `git init` command. I did that because the first time I want to commit and push everything into github but I realized that I did not pull yet. So, I used command `git pull` after `git add *` – lvarayut Aug 07 '13 at 15:39

0 Answers0