Skip to content

Instantly share code, notes, and snippets.

@mindplace
Last active November 27, 2024 08:25
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.

@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

@muhammadalizkhan
Copy link

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

! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/muhammadalizkhan/DairyPureAppHome.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.

@selfmanish01
Copy link

manish kumar@Professor MINGW64 ~/OneDrive/Desktop/CHAT_APP (main)
$ git remote add origin https://github.com/selfmanish01/Chat_Application

manish kumar@Professor MINGW64 ~/OneDrive/Desktop/CHAT_APP (main)
$ git push -u origin main
To https://github.com/selfmanish01/Chat_Application
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://github.com/selfmanish01/Chat_Application'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

manish kumar@Professor MINGW64 ~/OneDrive/Desktop/CHAT_APP (main)
$

getting this error, how to resolve this error.

@karandeep1836
Copy link

Thank you for this.

and in last step this worked for me:

git push -uf origin master

@Itun-u
Copy link

Itun-u commented Jul 15, 2024

Omo...

@Arshad0078
Copy link

It Worked perfectly fine , print("Thank You")

@puttu93739
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!

generate new token in developer settings and try

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