Skip to content

Instantly share code, notes, and snippets.

@mindplace
Last active March 28, 2024 20:18
Show Gist options
  • Save mindplace/b4b094157d7a3be6afd2c96370d39fad to your computer and use it in GitHub Desktop.
Save mindplace/b4b094157d7a3be6afd2c96370d39fad to your computer and use it in GitHub Desktop.
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: https://github.com/yourname/yourproject.git
    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 https://github.com/yourname/yourproject.git

  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.

@jallwork
Copy link

jallwork commented Jun 18, 2020 via email

@BhagyaSri22
Copy link

Thanks!

Copy link

ghost 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
Copy link

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

@Akashcool26
Copy link

This works well

@Msadr471
Copy link

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
Copy link

shirleym commented Sep 7, 2020

Thank you for the clear instructions

@kanishka424
Copy link

thanks for this!

@web3marketingkenya
Copy link

Link to refresher on using command line not working.

@davey555
Copy link

davey555 commented Dec 1, 2020

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

@imraann0
Copy link

imraann0 commented Dec 9, 2020

Thanks!!

@Mosespimor
Copy link

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

@Most-Wanted-21
Copy link

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
Copy link

Thanks

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

ghost commented Feb 12, 2021

Thank you very much

@KunalKing
Copy link

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
Copy link

Really great article. Thanks

@nihanyatir
Copy link

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

@sanjukk
Copy link

sanjukk commented Aug 26, 2021

Nice Elaboration,
Worked very well

@AEnyChris
Copy link

Thanks. Helped me

@OybekJP
Copy link

OybekJP commented Sep 14, 2021

Thanks, it was helpful!

Copy link

ghost commented Sep 26, 2021

I was unable to get this to work:

ashbu@DESKTOP-8NAGQ06 MINGW64 ~/Documents/trio_ircproxy
$ git remote add origin https://github.com/ashburry-chat-irc/trio_ircproxy.git
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?

@xiangzhang1015
Copy link

Easy to use! Thanks.

@mamutalib
Copy link

Thanks for this post.

@MichaelFrankMorris
Copy link

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 'https://github.com/..."

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 https://github.com/mindplace/test-repo.git
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.

@seamusdemora
Copy link

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!

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

...best 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 https://github.com/(your Github name)/repo name.git>
3. git branch -M main
4. git push -u origin main

This should work perfectly!!!

@brucekelley
Copy link

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.

@trillionclues
Copy link

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.

@tiva-OG
Copy link

tiva-OG commented Sep 12, 2022

Wow! This instructions are so clear and on-point.

However, I was faced with a little challenge at Step-4 in Section-3 (3. Connect your local project folder to your empty folder/repository on Github.). This was the error:
git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.

I took the steps from this solution, and I was back on track.

@trillionclues
Copy link

Yeah glad you found a solution to that!

Another solution to some permission errors would be creating a GitHub Personal Access Token(PAT) too.

@AliLtRP
Copy link

AliLtRP commented Sep 18, 2022

Thank you for this.

and in last step this worked for me:

git push -uf origin master

@pranalivk14
Copy link

For the error: failed to push some refs to.....
try 'master' instead of 'main' in git push -uf origin main

@gbengayaks
Copy link

gbengayaks commented Jan 13, 2023

please can someone help me solve this error
error: src refspec main does not match any

@mamutalib
Copy link

What you’re trying to do?

@eldorashur
Copy link

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.

if you already created readme file and you didn’t put much info in it you can use: git push --force -u origin master
it will remove your Readme file and push your local code to the git

@cterogene
Copy link

So helpful, Thank you.

@Enricocicc
Copy link

I'm getting Authentication failed when I enter my credential after the push command. I insert the correct ones but still get the error. Any help?

@honest888
Copy link

I think, to push the project to main branch, we need to add:
git branch -M main

or we can push the project to master branch
git push -u origin master

@anasrawuthar
Copy link

error: failed to push some refs to 'https://github.com/anasrawuthar/djangoweb.gi
t'

@anasrawuthar
Copy link

Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects
$ git init
Initialized empty Git repository in C:/Users/Anas/3D Objects/.git/

Anas@DESKTOP-PQVUR5J MINGW64 /3D Objects (master)
$ ^[[200

bash: $'\E[200~': command not found

Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects (master)
$

Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects (master)
$ git add .
warning: adding embedded git repository: static
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add static
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached static
hint:
hint: See "git help submodule" for more information.

Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects (master)
$ git commit -m "initial commit"
[master (root-commit) e0fc14d] initial commit
2 files changed, 1 insertion(+)
create mode 100644 desktop.ini
create mode 160000 static

Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects (master)
$ git remote add origin https://github.com/anasrawuthar/djangoweb.git

Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects (master)
$ git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/anasrawuthar/djangoweb.gi
t'

Anas@DESKTOP-PQVUR5J MINGW64 ~/3D Objects (master)

@honest888
Copy link

Hi anasrawuthar.
I think, you had already had a main branch in your git.
In this case, you can clone the main branch in your local and then copy your updates in the same folder.
And then you can use the git commit.

@lordbsqaure
Copy link

hello

@PaulAsaf2
Copy link

Thank you! You've got it all laid out.

@btreynor
Copy link

btreynor commented Aug 3, 2023

Thank you for all who helped

@MarcelAngulo
Copy link

I've been trying git push -u origin main. Git asks me the username and the password but then I can't type any password. Some people say that git doesn't show password for security reasons, but even if I type the password and press enter, doesn't push anything. Git throws:

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/MarcelAngulo/python-tetris.git/'

So I opened the link and read it but I don't understand what to do.
Please help!

@btreynor
Copy link

btreynor commented Aug 4, 2023

MarcelAngulo, have you already:

git init
git add .
git commit -m "initial commit"
Created a repository, copied the URL
git remote add origin [copied web address]?

All of this I found on: "https://gist.github.com/mindplace/b4b094157d7a3be6afd2c96370d39fad"
Hope this helps

Copy link

ghost commented Aug 7, 2023

This is the process I use. Just git add/commit/push with no mention of origin nor master nor main.
Any git commands wich mention origin or main or master I consider very old posted material.

git init         <-- Just once.
git add .
git commit -m "initial  commit"
git push

@satanpgn
Copy link

satanpgn commented Aug 8, 2023

i cannot push my folder into git hub please help me

@honest888
Copy link

honest888 commented Aug 8, 2023

Could you describe your situation more details?
What is your main issue?

@Ashit743
Copy link

MarcelAngulo, have you already:

git init git add . git commit -m "initial commit" Created a repository, copied the URL git remote add origin [copied web address]?

All of this I found on: "https://gist.github.com/mindplace/b4b094157d7a3be6afd2c96370d39fad" Hope this helps

make sure you have initiated git, or you are at wrong directory while running the command

@houserockr
Copy link

It took me hours to realise that master is now main on github. Whose idea was this????? F***ing stupid!

@MohammadWaris
Copy link

MohammadWaris commented Jan 9, 2024

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 'https://github.com/..."

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 https://github.com/mindplace/test-repo.git 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.

I have tried too many times it always asks me the authentication despite I am typing the correct email and password but it is not accepting, could you please guide me??
Thank you so much !
C:\Users\M.W.Khaliqyar\Desktop\new_Git_Practice>git push origin master
Logon failed, use ctrl+c to cancel basic credential prompt.
Username for 'https://github.com': MohammadWaris
Password for 'https://MohammadWaris@github.com':
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/MohammadWaris/practice.git/'

@seamusdemora
Copy link

@houserockr

It took me hours to realise that master is now main on github. Whose idea was this????? F***ing stupid!

Couldn't agree more. This is apparently an element of GitHub's "I'm Late to the Woke Party" bullshit... 'cause some will find the word "master" offensive. I'm beginning to wonder about GitHub... if this sort of thing is what they're focused on I'll be forced to find another website.

FWIW - I think this is "The MS Influence". I was prompted recently to add my "pronouns"... OK - I've complied with that request :)

@dgsung
Copy link

dgsung commented Mar 28, 2024 via email

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