Trying to upload existing git project

I created a git project; it is now ready to be moved over to be a github project, and I’m apprehensive about doing something (else) wrong.

I created a github project, it suggested a README file, so I checked that box and one to choose a license. But when I looked up how to transfer my own git project up to a github project, it said to use something on the “Quick Setup” page, which I could not find. On further investigation, it seems to be a page that appeared when I first created the project, and the instructions say “this page is important, so don’t close it”. Unfortunately I had already closed it before I read that instruction page.

So what’s my way back? If I delete the project, will I be able to recreate it WITH THE SAME NAME and get to the magic page? Or is there some way to proceed from here? I’m afraid to do much for fear of doing something else wrong.

The easiest thing will be to add the Github repository as a remote of your local one (see Working with Remotes), and then force-push to get exactly what you have locally to Github.

The one catch with that approach is that with the force-push you will lose the README and LICENSE files that were created when you choose to initialize the repository with them, if you want to keep them you should copy them to your local repository and commit them there before pushing.

If you go with this approach (after committing README and LICENSE, if you want), the process will be something similar to:

git remote add origin
git push --set-upstream --force origin main

Once again, pushing with --force will delete everything already on the same branch on Github. :warning:

I can re-add those things after the force, can’t I?

Or that, sure. I just figure it’d be easier to do before. :slightly_smiling_face:

Ok, read some git documentation and had lunch, then tried this.

First attempt failed; I think because I already have a ‘remote’ called ‘origin’; I set up a repository location on a network drive I have here at home and that’s called ‘origin’. So I altered the command to use a different name:

git remote add github
git push --set-upstream --force github main

I figured I would call this remote repo ‘github’.” is the string in the address bar on the browser when I’m looking at my github repository on the github website. However, I got the following error:

error: src refspec main does not match any.
error: failed to push some refs to ‘’

I don’t know what this means. I thought ‘main’ was the ‘branch’ I was on, so I don’t know what that first line means. Can you help me decode this, or tell me what’s wrong with my commands?

Well, actually the name of my branch is ‘master’, not ‘main’. I tried again with ‘master’ and got an authenticity problem Permission denied (publickey).
fatal: Could not read from remote repository.

Am looking into what I need to push to my own repository…

Most likely you need to add the SSH public key for your computer to your Github account:

1 Like

Many thanks for the excellent references - managed to add an SSH key and get the repo pushed. Now need to figure out how (and whether) to maintain two remotes, guess I don’t really need to.

1 Like

There’s nothing special about maintaining multiple remotes, you can just push to both. The only catch is that each branch can have only one configured upstream branch (where git push without any arguments goes, and git pull without any arguments pulls from).

So, to push your existing master branch to both, you can do:

git push origin master
git push github master
1 Like

Ok, thanks again. My current problem is that, while I can see on the Github site that I’ve pushed the stuff to “master”, it seems to want me to “issue a pull request” for it; it doesn’t look like it’s available to anyone else, I guess because I haven’t done that yet, but I haven’t figured out how to.

When I got to the project’s home page (, it says “master had recent pushes X minutes ago”, with a button that says “Compare and pull request”. When I click the button, it takes me to a page for “Comparing changes”; there’s a line that says “Choose two branches to see what’s changed or to start a new pull request.”, but it doesn’t say how to selected them. There’s a line before that that has “base: main” and “compare: master”; I gather that what I called ‘master’ it was calling ‘main’. I’ll be happy to merge master with main – main only has the (mostly empty) README file and the license file in it, I presume – But I don’t know how to start this ‘pull request’ that’s mentioned. Can you point me again?

Sorry for all basic questions. I don’t yet have a good model for how all this works.

Before you merge, the question is: How you want to have your branches? Which do you want to be your default branch? The default branch is the one you see when you open the repository page on Github, and it will be checked out by default if you do a fresh clone of your repository.

Documentation on how to create a pull request is here:

I ran into a similar situation … GitHub creates a repo with the ‘master’ branch called ‘main’; but, my local git called the ‘master’ branch ‘master’. Since almost all documentation I read refers to ‘master’, I just deleted the branch called ‘main’. Then my ‘master’ branch is called ‘master’. And I can use the command lines I find in documentation as they are written.

If you like the content of the README and LICENSE files, the simple solution to copy their content and paste it into similarly named files in your ‘master’ branch. Then you can ignore merging ‘master’ into ‘main’.

Thanks – what I ended up doing was just renaming the ‘master’ on my
local machine to ‘main’, then uploading. That worked.

1 Like