← Back to posts

Adding a Pre-Existing Website to GitHub

Colby Hemond

Colby Hemond

July 15, 2020
2 minutes

If you are like me, you don't use GitHub nearly as much as you should. Because of that, you always seem to forget how simple the process of the Git commands can be. Well, fear no more—you might as well bookmark this blog post before you even continue reading. In this post I will outline the following steps:

  1. Creating the Git repository on your local machine
  2. Creating the repository on GitHub
  3. Pushing the repository on your local machine to GitHub

Creating the Git repository on your local machine

First, open up your terminal and cd into the folder that contains your project. Usually it's just a simple:

cd your-project-here

Next, initialize the Git repository:

git init

Stage all project files for commit:

git add .
The . means you're adding everything in the folder.

Bonus: Add a .gitignore file

If you have sensitive files you don’t want tracked by Git (like .env files), do this:

touch .gitignore
git add .gitignore

Now commit everything:

git commit -m "uploading initial project"

Your project is now committed locally. Next, let’s get it onto GitHub.

Creating the repository on GitHub

  1. Go to github.com and log in
  2. Click the + in the top-right corner → New Repository
  3. Name the repo (ideally the same as your project folder)
  4. Adjust settings as needed
  5. Click Create Repository

You now have an empty repo online. Next step: connect it to your local repo.

Pushing the repository on your local machine to GitHub

Back in the terminal, link your local repo to GitHub:

git remote add origin https://github.com/username/new_repo
Replace username with your GitHub username, and new_repo with your actual repository name.

Optional: Use SSH instead

If you have SSH set up:

git remote add origin git@github.com:username/new_repo

Set up SSH (GitHub Docs)

Now push your files:

git push -u origin master

That’s it! 🎉 Head back to GitHub and refresh the page—you should now see all your project files.

Hope this helped you as much as it’s going to help me next time I forget 😄

git
github