Home > Blockchain >  If I have a local repo already, how do I upload it to a remote empty/new repo?
If I have a local repo already, how do I upload it to a remote empty/new repo?

Time:04-01

I have this local project inside a folder that I have not used git init yet. I've already setup a new repo on github and I wanted to upload this existing project to this new repo. Unfortunately, following this would not work:

…or push an existing repository from the command line

git remote add origin https://github.com/Kas1680/TrailSquirrel.git
git branch -M main
git push -u origin main

I just want a simple "upload this local repo to a new remote repo". Tried googling already but no avail. Also tried cloning it. It won't let me add/commit

CodePudding user response:

I have not used git init yet.

You haven't done git init? And you haven't set up the repository with some other tool already? At all?

Then it's not a Git repository. It's just some files on your PC. The other git commands don't work because it's not an actual Git repository. You have to initialize it with git init first.

Now, what you seem to want to do is a bit different than that. What you seem to want is to take a bunch of existing files, and add them to an existing repository. That's different from "migrating a repository" as you seem to be trying to do.

Assuming that is correct, here's what you actually need to do:

  • git clone into the repository you've created.
  • Move your project files to the newly-cloned repository.
  • git add all the new files.
  • git commit the addition
  • git push the changes to your repository.

You will likely need to follow additional steps (such as logging in and setting your upstream branch) but the command line will explain these to you when they're needed.

Also, as a side note, you've left your real GitHub link live in the example. You might want to remove that. If you're just going to copy/paste command line arguments then I'd suggest using a GUI tool like GitHub Desktop rather than using the commandline. It will be easier and faster.

CodePudding user response:

First off, you need to run git init in your local folder. Nothing is going to work unless you initialize git in your folder first. After which, you can do the follow.

git remote add origin https://github.com/Kas1680/TrailSquirrel.git 

This will add the local repo to the remote repo. From there, you are free to make a commit and push and it should appear in github.

  • Related