Skip to content

Instantly share code, notes, and snippets.

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

Make sure git is tracking your project.

  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.

  1. 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 by typing git init, then going through the process of adding and committing your project.

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 your error and/or output to understand it, and to figure out how to fix it.

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


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.


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'.

Copy the link in the input right beneath the title, it should look something like this: https://github.com/mindplace/test-repo.git This is the web address that your local folder will use to push its contents to the remote folder on Github.

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

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

Example: git remote add origin https://github.com/mindplace/test-repo.git

  1. Push your branch to Github: git push origin master

  2. 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.

@ashish5678

This comment has been minimized.

Copy link

@ashish5678 ashish5678 commented Feb 2, 2018

1

@ashish5678

This comment has been minimized.

Copy link

@ashish5678 ashish5678 commented Feb 2, 2018

hi

@narendrabade

This comment has been minimized.

Copy link

@narendrabade narendrabade commented Feb 7, 2018

thanks for this nice article.

@dgsung

This comment has been minimized.

Copy link

@dgsung dgsung commented Apr 21, 2018

thank you!

@Nena15

This comment has been minimized.

Copy link

@Nena15 Nena15 commented Apr 23, 2018

Thanks! <3

@RamanaYalakala

This comment has been minimized.

Copy link

@RamanaYalakala RamanaYalakala commented May 21, 2018

nice

@asimmazari

This comment has been minimized.

Copy link

@asimmazari asimmazari commented May 28, 2018

how i copy my pro to github

@pravinwadkar33

This comment has been minimized.

Copy link

@pravinwadkar33 pravinwadkar33 commented Jun 24, 2018

Hi,
I have created project using IntelIJ i want to upload to git.. Could u please help me on this ?

@Pawanjaju

This comment has been minimized.

Copy link

@Pawanjaju Pawanjaju commented Jul 3, 2018

Hi,
I tried all the steps & i got this error
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/Pawanjaju/gnpconsultancy.git'

@atul8680

This comment has been minimized.

Copy link

@atul8680 atul8680 commented Jul 8, 2018

i also got the same error as @Pawanjaju.

@chwaee

This comment has been minimized.

Copy link

@chwaee chwaee commented Jul 8, 2018

@Pawanjaju and @atul8680, I found the fix for that error to be the below. I'm not exactly sure how it all works, but I had to use the "-f" for force on the first commit. With the push command, you will need to provide your github credentials.

https://stackoverflow.com/questions/4181861/src-refspec-master-does-not-match-any-when-pushing-commits-in-git

git remote add origin /path/to/origin.git
git add .
git commit -f -m "initial commit"
git push origin master

I should also note that you should copy the README.md file locally before this commit and push, otherwise you will lose it. Probably a better method would be to do a pull first then commit and push.

@raytroop

This comment has been minimized.

Copy link

@raytroop raytroop commented Jul 20, 2018

Thanks, but there are official tutorials

@123sadhnajuhirdeen

This comment has been minimized.

Copy link

@123sadhnajuhirdeen 123sadhnajuhirdeen commented Jul 30, 2018

@chwaee is correct. that is the exact solution for you both problem @Pawanjaju and @atul8680,

@ATMA1234

This comment has been minimized.

Copy link

@ATMA1234 ATMA1234 commented Sep 3, 2018

iam not able to do commit in github. but repositories are creating.

@maandar321

This comment has been minimized.

Copy link

@maandar321 maandar321 commented Oct 9, 2018

thanks

@harshitasinari

This comment has been minimized.

Copy link

@harshitasinari harshitasinari commented Oct 12, 2018

This article is very helpful for beginners.thank you

@HarplingeTom

This comment has been minimized.

Copy link

@HarplingeTom HarplingeTom commented Oct 20, 2018

this almost worked, but it didn't. I had to use the "git push -u" command. I'm new to this so I don't know why your suggestion to simply use "git push" without the flag didn't work for me.

@zaarab001

This comment has been minimized.

Copy link

@zaarab001 zaarab001 commented Oct 21, 2018

Thank you! I love this article

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Nov 14, 2018

@avinash321

This comment has been minimized.

Copy link

@avinash321 avinash321 commented Nov 19, 2018

thank you..

@arminia

This comment has been minimized.

Copy link

@arminia arminia commented Dec 14, 2018

Thanks, it really helped!

@sapna1611

This comment has been minimized.

Copy link

@sapna1611 sapna1611 commented Dec 15, 2018

thanks a lot for this

@diegosps

This comment has been minimized.

Copy link

@diegosps diegosps commented Jan 9, 2019

Ty! Helped a git noob here

@mutyala-s

This comment has been minimized.

Copy link

@mutyala-s mutyala-s commented Jan 21, 2019

good

@hassanarshad115

This comment has been minimized.

Copy link

@hassanarshad115 hassanarshad115 commented Jan 24, 2019

Don't worry its Very easy way without command prompt ..
just watch this video please.
https://youtu.be/7bVxmYOuHYo

@sulemankhan1

This comment has been minimized.

Copy link

@sulemankhan1 sulemankhan1 commented Feb 7, 2019

Followed the Same steps but got this in the console.

To https://github.com/sulemankhan1/simpleJsChatApp.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/sulemankhan1/simpleJsChatApp.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

@kmishal

This comment has been minimized.

Copy link

@kmishal kmishal commented Feb 10, 2019

Thanks.. !

@slysch

This comment has been minimized.

Copy link

@slysch slysch commented Feb 14, 2019

This was really helpful buddy. Big UP!

@kirasiris

This comment has been minimized.

Copy link

@kirasiris kirasiris commented Feb 28, 2019

Thank you so much for this!

@gratefulgirl

This comment has been minimized.

Copy link

@gratefulgirl gratefulgirl commented Mar 19, 2019

yeah thanks so much

@manojkumarhcm9

This comment has been minimized.

Copy link

@manojkumarhcm9 manojkumarhcm9 commented Mar 22, 2019

! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/manojkumarhcm9/test-repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

@ankit11421

This comment has been minimized.

Copy link

@ankit11421 ankit11421 commented Mar 28, 2019

! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/manojkumarhcm9/test-repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Try this : git pull origin master --allow-unrelated-histories
Then : git push origin master

@IshaAmbaniFansClub

This comment has been minimized.

Copy link

@IshaAmbaniFansClub IshaAmbaniFansClub commented Mar 29, 2019

Hi Sir
whatever you said same as and same application am push to my first application to git that time am get the error
This is : error: failed to push some refs to 'https://githu
how to solve the this error
pplease help me

@kripashetty

This comment has been minimized.

Copy link

@kripashetty kripashetty commented Apr 11, 2019

Thanks this is a good source to quickly refresh ones memory !!

@gautam890

This comment has been minimized.

Copy link

@gautam890 gautam890 commented Apr 20, 2019

@ishaAmbanifans :

try following commands in your local project:
git add --all
git commit -m "message you want for your first commit"
git push

@davesabra

This comment has been minimized.

Copy link

@davesabra davesabra commented Apr 29, 2019

error- remote origin already exists
(sure hope it does!)
will try git add --all

@davesabra

This comment has been minimized.

Copy link

@davesabra davesabra commented Apr 29, 2019

thankyou chwaee,
yours was the closest solution for me, the following worked;

git remote add origin /path/to/origin.git
git add
git commit -m "initial commit"
git push origin master
i) the -f option no longer exists
ii) as I noob I was sweating, it looked for a while like I could only push files (like individual scripts) rather than a folder

@plato1123

This comment has been minimized.

Copy link

@plato1123 plato1123 commented May 6, 2019

Good catch, davesabra.

@2bona

This comment has been minimized.

Copy link

@2bona 2bona commented May 16, 2019

thank you for this

@p-gold

This comment has been minimized.

Copy link

@p-gold p-gold commented May 25, 2019

i encountered the same problem, it stopped my workflow for days but after critical researches, i found out that the -f flag can be used with git, behold i used it and it worked. am relieved a bit for now. wooooooow!!!

@APandaInFjord

This comment has been minimized.

Copy link

@APandaInFjord APandaInFjord commented May 31, 2019

I stuck in the second last step

I got

error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/APandaInFjord/test.git'

Can anyone help? I tried every suggestion on Stackoverflow and they dont work for me.

@APandaInFjord

This comment has been minimized.

Copy link

@APandaInFjord APandaInFjord commented May 31, 2019

! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/manojkumarhcm9/test-repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Try this : git pull origin master --allow-unrelated-histories
Then : git push origin master

When I tried the first line, I got fatal: couldn't find remote ref master

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jun 7, 2019

thanks alot

@HamoudaJoe

This comment has been minimized.

Copy link

@HamoudaJoe HamoudaJoe commented Jun 25, 2019

thanks :)

@menkrep1337

This comment has been minimized.

Copy link

@menkrep1337 menkrep1337 commented Jun 29, 2019

thx

@thisilvafarias

This comment has been minimized.

Copy link

@thisilvafarias thisilvafarias commented Jul 1, 2019

I got the same error error: failed to push some refs to 'https://github.com/*****

But following this order it worked:

git init
git add .
git commit -m "First commit"
#Go to https://github.com --- Create a new repository (without README.md)
git remote add origin https://github.com/userProfile/projectName.git
git push -u origin master

@victuk

This comment has been minimized.

Copy link

@victuk victuk commented Aug 13, 2019

iam not able to do commit in github. but repositories are creating.

git push origin master -f

@sanikadjango

This comment has been minimized.

Copy link

@sanikadjango sanikadjango commented Aug 24, 2019

! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/manojkumarhcm9/test-repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Try this : git pull origin master --allow-unrelated-histories
Then : git push origin master

Thanks ...this worked

@rlr842011

This comment has been minimized.

Copy link

@rlr842011 rlr842011 commented Aug 29, 2019

Thank you! I'm a newbie. This was easy to follow along with.

@railsfactory-pavan

This comment has been minimized.

Copy link

@railsfactory-pavan railsfactory-pavan commented Sep 5, 2019

git push origin master -f

is works for me

@antoniobeno

This comment has been minimized.

Copy link

@antoniobeno antoniobeno commented Sep 18, 2019

git push origin master -f

is works for me

For me too. Thanks!

@AhmedRazaAttari

This comment has been minimized.

Copy link

@AhmedRazaAttari AhmedRazaAttari commented Sep 30, 2019

! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/manojkumarhcm9/test-repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Try this : git pull origin master --allow-unrelated-histories
Then : git push origin master

Thank's its worked

@lizkolk

This comment has been minimized.

Copy link

@lizkolk lizkolk commented Oct 2, 2019

interesting

@DroppedSyn

This comment has been minimized.

Copy link

@DroppedSyn DroppedSyn commented Oct 24, 2019

Lovely!

@SigmaDemon

This comment has been minimized.

Copy link

@SigmaDemon SigmaDemon commented Nov 12, 2019

! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/manojkumarhcm9/test-repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Try this : git pull origin master --allow-unrelated-histories
Then : git push origin master

Your advice saved my freakin' life! God Bless You! :))))))))))

@LeiladosSantos11

This comment has been minimized.

Copy link

@LeiladosSantos11 LeiladosSantos11 commented Dec 28, 2019

Thank you!

@Sreek-Swarnapuri

This comment has been minimized.

Copy link

@Sreek-Swarnapuri Sreek-Swarnapuri commented Jan 4, 2020

Thank you for the easy to use Article!!!

@koreshdone

This comment has been minimized.

Copy link

@koreshdone koreshdone commented Feb 8, 2020

the site configured at this address does not contain the requested file

@koreshdone

This comment has been minimized.

Copy link

@koreshdone koreshdone commented Feb 8, 2020

What is the error
It's asking index.html

@akashjadhav3

This comment has been minimized.

Copy link

@akashjadhav3 akashjadhav3 commented Feb 21, 2020

! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/manojkumarhcm9/test-repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Try this : git pull origin master --allow-unrelated-histories
Then : git push origin master

Thank you it worked for me

@IwonGunawan

This comment has been minimized.

Copy link

@IwonGunawan IwonGunawan commented Feb 25, 2020

Thank you .
is work for me.

@nyapayo

This comment has been minimized.

Copy link

@nyapayo nyapayo commented Mar 2, 2020

! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/nyapayo/allrestau.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

@nyapayo

This comment has been minimized.

Copy link

@nyapayo nyapayo commented Mar 2, 2020

please help me

@snlaccount

This comment has been minimized.

Copy link

@snlaccount snlaccount commented Mar 14, 2020

if you have already created a project and then adding in git repo which is created with readme file you might get below error.
error: src refspec master does not match any
error: failed to push some refs to
Try these. This will set your local repo first to track to remote and then push changes
git init
git pull
git commit -m "first commit"
git push -u origin master

@SaraSherifM

This comment has been minimized.

Copy link

@SaraSherifM SaraSherifM commented Mar 19, 2020

I have no idea why but this no longer works for me!even though I follow the exact same steps

@jyotijain0308

This comment has been minimized.

Copy link

@jyotijain0308 jyotijain0308 commented Apr 19, 2020

Thank You, It was really helpful.

@2vishnui

This comment has been minimized.

Copy link

@2vishnui 2vishnui commented Apr 19, 2020

@ishaAmbanifans :

try following commands in your local project:
git add --all
git commit -m "message you want for your first commit"
git push

this worked for me

also email was private. so needed to make it public

@johriexp

This comment has been minimized.

Copy link

@johriexp johriexp commented May 15, 2020

Many thanks for this wonderful article.

@Bob160

This comment has been minimized.

Copy link

@Bob160 Bob160 commented Jun 2, 2020

I don't know why but this no longer works for me.

Its been a couple of months since I pushed my last project but upon trying to push a new project today, I found after creating the new repo that the code/ link (needed for the git remote add origin bla bla) is not being provided again. I had to resort to upload my codes as files.
What's going on? Is this the latest now?
Someone please advise, thanks.

@jallwork

This comment has been minimized.

Copy link

@jallwork jallwork commented Jun 16, 2020

I get the same error message as @Pawanjaju:
Trying your solution: git commit -f -m "initial commit"
Gives me the error message:

error: unknown switch `f'

@PunningPasta

This comment has been minimized.

Copy link

@PunningPasta PunningPasta commented Jun 18, 2020

@chwaee I'm hoping you can help me I've done everything the scrip said and I've done what you've written but one I get to the last step it says this!: git push origin master
remote: Repository not found.
fatal: repository 'https://github.com/PunningPasta/Project0_Done.git/' not found
But I have the repository opened? and everything is done exactly as stated so I'm really confused? I've just started learning how to use git and github so please be patient with me thank you!

@Bob160

This comment has been minimized.

Copy link

@Bob160 Bob160 commented Jun 18, 2020

@PunningPasta did you delete the forked repo from your account? This may explain why. Check and if so, refork, reclone and start making your changes anew. Welcome to git and GitHub. All the best!

@jallwork

This comment has been minimized.

Copy link

@jallwork jallwork commented Jun 18, 2020

@jallwork

This comment has been minimized.

Copy link

@jallwork jallwork commented Jun 18, 2020

@BhagyaSri22

This comment has been minimized.

Copy link

@BhagyaSri22 BhagyaSri22 commented Jul 14, 2020

Thanks!

@shreyasikatiyar

This comment has been minimized.

Copy link

@shreyasikatiyar 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.

@MilosCodes

This comment has been minimized.

Copy link

@MilosCodes MilosCodes commented Aug 2, 2020

There is Good video of how to use Github https://www.youtube.com/watch?v=iv8rSLsi1xo

@Akashcool26

This comment has been minimized.

Copy link

@Akashcool26 Akashcool26 commented Aug 12, 2020

This works well

@Msadr471

This comment has been minimized.

Copy link

@Msadr471 Msadr471 commented Aug 23, 2020

I have a problem with this ...

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

and then GitHub Desktop gives me this error:

image

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 ?!

@shirleym

This comment has been minimized.

Copy link

@shirleym shirleym commented Sep 7, 2020

Thank you for the clear instructions

@kanishka424

This comment has been minimized.

Copy link

@kanishka424 kanishka424 commented Oct 29, 2020

thanks for this!

@Dominic-Otieno

This comment has been minimized.

Copy link

@Dominic-Otieno Dominic-Otieno commented Oct 29, 2020

Link to refresher on using command line not working.

@davey555

This comment has been minimized.

Copy link

@davey555 davey555 commented Dec 1, 2020

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

@imraann0

This comment has been minimized.

Copy link

@imraann0 imraann0 commented Dec 9, 2020

Thanks!!

@Mosespimor

This comment has been minimized.

Copy link

@Mosespimor Mosespimor commented Dec 10, 2020

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

@Most-Wanted-21

This comment has been minimized.

Copy link

@Most-Wanted-21 Most-Wanted-21 commented Dec 17, 2020

I got the same error error: failed to push some refs to 'https://github.com/*****

But following this order it worked:

git init
git add .
git commit -m "First commit"
#Go to https://github.com --- Create a new repository (without README.md)
git remote add origin https://github.com/userProfile/projectName.git
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.

@Derry-ukere

This comment has been minimized.

Copy link

@Derry-ukere Derry-ukere commented Jan 11, 2021

Thanks

@ahctun

This comment has been minimized.

Copy link

@ahctun 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

@vadokin

This comment has been minimized.

Copy link

@vadokin vadokin commented Feb 12, 2021

Thank you very much

@KunalKing

This comment has been minimized.

Copy link

@KunalKing 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.

@Leumastai

This comment has been minimized.

Copy link

@Leumastai Leumastai commented Jun 14, 2021

Really great article. Thanks

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