Skip to content

Instantly share code, notes, and snippets.

Embed
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: 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.

@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

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.

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