Adding an existing project to GitHub using the command line

  1. Create a new repository on GitHub. You can also add a gitignore file, a readme, and a license if you want
  2.  Open Git Bash
  3. Change the current working directory to your local project.
  4. Initialize the local directory as a Git repository.
    git init
  5. Add the files to your new local repository. This stages them for the first commit.
    git add .
  6.  Commit the files that you’ve staged in your local repository.
    git commit -m "initial commit"
  7.  Copy the HTTPS URL of your newly created repo
  8. In the Command prompt, add the URL for the remote repository where your local repository will be pushed.

    git remote add origin remote repository URL

    git remote -v
  9.  Push the changes in your local repository to GitHub.

    git push -f origin master

That’s all

This page is brought to you thanks to our main sponsor Collaboard.
Collaboard is an online real-time whiteboard that allows you and your team to exchange ideas and to go beyond the limits of a virtual meeting. Start thinking differently together and drive innovative results. Bring collaboration to the next level!
Give it a try, there is also a 100% free subscription. 

Show More

Related Articles


  1. Loved this article. It could be improved by slightly changing the formatting of the second command in step 8 a little bit so that its easier to tell which parts are part of the command and which parts are placeholders. For example: ‘git remote add origin remote_repository_URL’.

  2. From my DOS command line I ran the following command
    git remote add origin remote repository

    and I received the following error

    usage: git remote add []

    -f, –fetch fetch the remote branches
    –tags import all tags and associated objects when fetching
    or do not fetch any tag at all (–no-tags)
    -t, –track branch(es) to track
    -m, –master
    master branch
    set up remote as a mirror to push to or fetch from

  3. Thanks so much, so simple … Although while trying out commands I skipped git remote -v
    by mistake.
    After git remote add origin remote repository URL
    Directly entered git push -f origin master
    It worked though.

    So what’s the use of git remote -v

  4. Hi,
    well, it’s a somewhat old article, but I wanted to leave a thank you.
    Maybe the part ‘git remote add origin remote repository URL’ will be more clear if you put ‘remote repository URL’ into quotes. As a newby I made this mistake 🙂

  5. Great quick little hint! I would update the post this way to avoid some confusion:

    8. In the Command prompt, add the URL for the remote repository where your local repository will be pushed.

    git remote add origin remote-repository-URL

    I don’t know enough git to even be dangerous so it took me a minute to figure out “remote repository URL” wasn’t a list of git commands.

Leave a Reply to gagan sharma Cancel reply

Your email address will not be published. Required fields are marked *

Back to top button