Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Pushing your first project to github

1. Make sure git is tracking your project locally

Do you need a refresher on git? Go through Codecademy's git course.

  1. Using your terminal/command line, get inside the folder where your project files are kept: cd /path/to/my/codebase. → You cannot do this simply by opening the folder normally, you must do this with the command line/terminal.
    → Do you need a refresher on using your command line/terminal? I've compiled my favorite resources here.

  2. Check if git is already initialized: git status
    If you get this error message: fatal: Not a git repository (or any of the parent directories): .git, that means the folder you are currently in is not being tracked by git. In that case, initialize git inside your project folder and make your first commit:

    git init
    git add .
    git commit -m "initial commit"

    → If you get another error message, read carefully what it says.

    • Is it saying git isn't installed on your computer by saying that the word 'git' is not recognized?
    • Is it saying that you're already in a folder or sub-folder where git is initialized?
    • Google the error output to understand it, and to figure out how to fix it.

2. Create a remote, empty folder/repository on Github.

  1. Login to your Github account.

  2. At the top right of any Github page, you should see a '+' icon. Click that, then select 'New Repository'.

  3. Give your repository a name--ideally the same name as your local project. If I'm building a travel application, its folder will be called 'travel-app' on my computer, and 'travel-app' will be the Github repository name as well.

  4. Click 'Create Repository'. The next screen you see will be important, so don't close it.

3. Connect your local project folder to your empty folder/repository on Github.

The screen you should be seeing now on Github is titled 'Quick setup — if you’ve done this kind of thing before'.

  1. Copy the link in the input right beneath the title, it should look something like this:
    This is the web address that your local folder will use to push its contents to the remote folder on Github.

  2. Go back to your project in the terminal/command line.

  3. In your terminal/command line, type git remote add origin [copied web address] Example: git remote add origin

  4. Push your branch to Github: git push -u origin main

  5. Go back to the folder/repository screen on Github that you just left, and refresh it. The title 'Quick setup — if you’ve done this kind of thing before' should disappear, and you should see your files there.

Copy link

jallwork commented Jun 18, 2020

Copy link

BhagyaSri22 commented Jul 14, 2020


Copy link

shreyasikatiyar commented Jul 27, 2020

As a beginner, it helped a lot! No need to go anywhere else. Including the expected error helped to find the desired solution.

Copy link

MilosCodes commented Aug 2, 2020

There is Good video of how to use Github

Copy link

Akashcool26 commented Aug 12, 2020

This works well

Copy link

Msadr471 commented Aug 23, 2020

I have a problem with this ...

how can I create a new repository from CDM on windows?
wich command, should I use to publish a new repository ???

and then GitHub Desktop gives me this error:


I read all issue of this problem but doesn't work!

It is much easier to use the desktop version, but I do not know why it has this problem ?!

Copy link

shirleym commented Sep 7, 2020

Thank you for the clear instructions

Copy link

kanishka424 commented Oct 29, 2020

thanks for this!

Copy link

Dominic-Otieno commented Oct 29, 2020

Link to refresher on using command line not working.

Copy link

davey555 commented Dec 1, 2020

thanks alot, this really helped me to clearly understand very well.

Copy link

imraann0 commented Dec 9, 2020


Copy link

Mosespimor commented Dec 10, 2020

This was absolutely amazing and helpful as a beginner. Thanks!

Copy link

Most-Wanted-21 commented Dec 17, 2020

I got the same error error: failed to push some refs to '*****

But following this order it worked:

git init
git add .
git commit -m "First commit"
#Go to --- Create a new repository (without
git remote add origin
git push -u origin master

You saved me!! I think I just forgot to use "git init" originally when I committed changes. Then I cloned to GitKraken which made more of a mess, but figured out how to delete local copy in folders.

Copy link

Derry-ukere commented Jan 11, 2021


Copy link

ahctun commented Feb 9, 2021

To push a local repository to GitHub, the official guide now recommends that we use the following commands:

git remote add origin [your github repo's address]
git branch -M main
git push -u origin main

Copy link

vadokin commented Feb 12, 2021

Thank you very much

Copy link

KunalKing commented Mar 7, 2021

step 1 - Create a git repo from your GitHub home page. Click on create a new repo name it as per your project.
step 2 - Click on add files.
step 3- open your project folder, drag and drop your project files in your repo.
that's it.

Copy link

Leumastai commented Jun 14, 2021

Really great article. Thanks

Copy link

nihanyatir commented Jul 28, 2021

This is by far the most detailed tutorial. Much appreciated!

Copy link

sanjukk commented Aug 26, 2021

Nice Elaboration,
Worked very well

Copy link

AEnyChris commented Sep 6, 2021

Thanks. Helped me

Copy link

OybekJP commented Sep 14, 2021

Thanks, it was helpful!

Copy link

ashburry-chat-irc commented Sep 26, 2021

I was unable to get this to work:

ashbu@DESKTOP-8NAGQ06 MINGW64 ~/Documents/trio_ircproxy
$ git remote add origin
fatal: not a git repository (or any of the parent directories): .git

I downloaded my repo on to my new computer now I want to work on it.
Should it not ask me to log in first?

Copy link

xiangzhang1015 commented Oct 17, 2021

Easy to use! Thanks.

Copy link

mamutalib commented Dec 23, 2021

Thanks for this post.

Copy link

MichaelFrankMorris commented Feb 5, 2022

Page needs update. 2/5/22.
It's why people are getting errors since the master/main default conversion.

If "git push origin master"
produces error
"src refspec master does not match any
error: failed to push some refs to '"

Instead try "git push origin main"

There was general default update from 'master' to 'main'.... but that has not yet propagated to this page.

"... your terminal/command line, type git remote add origin [copied web address]
Example: git remote add origin
Push your branch to Github: git push origin master"

The last word "master" should now (if defaults are used) be "main"

Thank you.
Have a great day.

Copy link

seamusdemora commented Apr 28, 2022

Great Gist, thanks. It helped me - but as others have noted, it needs an update. In particular, the authentication part is missing. I had hoped that the new gh CLI would resolve all of that rather convoluted authentication business - just as the GitHub Desktop did for Desktops. But oddly, the GitHub people are saying that the deliberately left commit & push out of gh CLI because it wasn't useful!?!? Thanks again!

Copy link

trillionclues commented May 3, 2022

If you still run into this issue in 2022...i.e you want to push an existing repository from your VSCode to follow this pact

1. Create an empty repo(don't tick the 'CREATE README" option) on GitHub
2. git remote add origin <repo URL ie Github name)/repo name.git>
3. git branch -M main
4. git push -u origin main

This should work perfectly!!!

Copy link

brucekelley commented Jul 21, 2022

Definitely needs updating. Through a half hour of trial and error, I found that this tutorial gets off track if you check the box to "create Readme". Yeah, don't do that and it will go much smoother.

Copy link

trillionclues commented Jul 22, 2022

Definitely needs updating. Through a half hour of trial and error, I found that this tutorial gets off track if you check the box to "create Readme". Yeah, don't do that and it will go much smoother.
Yeah thanks for adding to that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment