In the last section we created a new repository in GitHub and then cloned it to our local machine. But, what if you've already been working on a project locally, and want to start tracking it with Git and use GitHub as the remote central repo? That's actually really simple to setup, so let's jump in!

We'll start out by creating a new repo like we did last time, but choose some different options that will let us use our existing repo.

  • Click the "plus" icon at the top of the GitHub page next to your user name
  • Select "New repository"
    • Owner: (Unless you're a part of an organization, your name will be the only option. If you are a part of an organization, you can choose to make the organization the repository owner.)
    • Repository name: My Existing Git Project (Name the repository.)
    • Description (optional): This is a project that I was working on locally, and am now pushing to GitHub.
    • [x] Public (I'm going to make this a public repo, but if you need to create a private one, select "Private" and enter your billing information.)
    • [ ] Initialize this repository with a README (Since I'm going to upload a Drupal site, and it already has a README.txt file, I'll leave this unchecked.)
    • When you download Drupal, it also comes with a .gitignore file already setup like we saw in the video Ignoring Specific Files, Folders and Patterns with the .gitignore File so I won't select one here.
    • You can also specify the license for this project, but again, Drupal comes with a LICENSE.txt file, so I'll leave this set to "None"
    • Click "Create repository"

This time around, we're shown a "Quick setup" section with the repo URL so that you can quickly clone the repo to your local machine. But, we want to use our existing repo, so we're going to skip down to the "…or push an existing repository from the command line" section.

(Note: In order to use an existing repo, it must already be initialized and have files added and committed to the repository locally.)

I'll move into the Drupal directory where I've initialized the git repo and follow their directions

  • I'll type "cd /var/www/mygitwebsite" and press Enter
  • Then on the GitHub page, select "SSH" to use the SSH Key we uploaded for authentication
  • Then copy and paste the first command from the GitHub page "git remote add origin git@github.com:ModulesUnraveledScreencast/My-Existing-Git-Project.git" (This sets the GitHub repo as the central remote. There's no confirmation when this works correctly, but you can confirm that it did by typing "git config --list". If it worked you'll see the line "remote.origin.url="git@github.com:ModulesUnraveledScreencast/My-Existing-Git-Project.git".)
  • Then copy and paste the second command "git push -u origin master" (This pushes the contents of the local repo to GitHub so that they are in sync.)

When the push is complete, you'll see the message "Branch master set up to track remote branch master from origin." This means that my local copy is configured to sync with the remote copy on GitHub.

Now, if we click the "My-Existing-Git-Project" link at the top of the page, we'll see all of the files that make up our Drupal site, and the contents of the README.txt file. So, we're all set!