How to Push an Existing Project to GitHub

Nicholas Cerminara
👁️ 54,029 views
💬 comments

[GitHub]1 is simply a cloud-hosted Git management tool. Git is distributed version control, meaning the entire repo and history lives wherever you put it. People tend use GitHub though in their business or development workflow as a managed hosting solution for backups of their repositories.

It's an ultra-convenient and mostly worry-free method for backing up all your code repos. It also allows you to very nicely navigate and view your code on the web. GitHub takes this even further by letting you connect with coworkers, friends, organizations, and more.

Putting an existing project on GitHub is actually very easy. You could just clone a blank repo then drag and drop some files, but that's never any fun. Below is a simple and quick method from the command line.

Table of Contents

    Step 1: Create a Repo

    This involves logging into GitHub and creating the repo. You can choose to either initialize a README or not. It doesn't really matter because we're just going to override everything in this remote repository anyways.

    Screen Shot 2014-03-04 at 10.34.00 PM

    Step 2: Initialize Git in the project folder

    From your terminal and assuming Git is already installed on your computer, run the following commands after navigating to folder you would like to add:

    Initialize the Git Repo

    
    git init
    
    

    Add the files to Git index

    
    git add -A
    
    

    Commit Added Files

    
    git commit -m 'Added my project'
    
    

    Add new remote origin (in this case, GitHub)

    
    git remote add origin git@github.com:scotch-io/my-new-project.git
    
    

    Push to GitHub

    
    git push -u -f origin master
    
    

    With this, there are a few things to note. The -f flag stands for force. This will automatically overwrite everything in the remote directory. We're only using it here to overwrite the README that GitHub automatically initialized. If you skipped that, the -f flag isn't really necessary.

    The -u flag sets the remote origin as the default. This lets you later easily just do git push and git pull without having to specifying an origin since we always want GitHub in this case.

    All together

    
    git init
    git add -A
    git commit -m 'Added my project'
    git remote add origin git@github.com:scotch-io/my-new-project.git
    git push -u -f origin master
    
    

    Additional Resources