1

I wanted to put my local code into a GitHub repository.

I created a repo on GitHub and tried cloning with HTTPS.
The clone was taking a moment but the folder was created on my laptop so I decided to cut/paste my local code into the local repo folder.

Well, the clone ended up failing and the repo folder just disappeared, along with all of its contents.
The folder I added to the local repo also disappeared.
I can't even find it in the recycling bin. Is it gone forever?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    Probably. Good thing you have backups. You have backups, right? – knittl May 12 '22 at 16:58
  • You made me chuckle knittl, but be kind, we've all been there without backups. – TheIceBear May 12 '22 at 17:10
  • Specifically, what does "the clone ended up failing" mean? – ChrisGPT was on strike May 12 '22 at 20:31
  • Yes: when you run `git clone`, the first step that Git does is make a new empty directory (or use an empty directory that you tell it to use) to hold a new empty repository (the `.git` sub-directory). If the clone step fails, Git removes the empty directory it created, and to do that, it has to remove all of its content first. In a somewhat nasty bug—long fixed now—Git used to remove that empty directory even if `git clone` was using one you supplied yourself! – torek May 12 '22 at 22:14
  • It wasn't too bad of a bug since `git clone` wouldn't run if the directory you supplied *wasn't* empty, but it was clearly wrong, and resulted in losing folders you moved into that initially-empty directory: i.e., exactly the loss you've just experienced. – torek May 12 '22 at 22:15

1 Answers1

0

Next time:

  • make sure you have installed gh, the GitHub CLI
  • create a repository locally where your code is
  • publish to GitHub (that will create the remote repository)

That way, no clone, no hazardous code migration.

The command to create the remote repository is (after a gh auth login):
gh repo create.

Inside a git repository, and with no arguments, gh will automatically create a repository on GitHub on your account for your current directory, using the directory name.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250