Skip to content

Creating a Repository on GitHub

Creating a GitHub repository is the first step toward publishing your code online. The form is simple, but a few choices you make during creation affect how you connect the repo to your local project — so it is worth understanding what each option does.

  1. Log into GitHub and click the + icon in the top-right corner, then “New repository.”

  2. Fill in the details:

Repository name — The name becomes part of the URL: github.com/yourusername/repository-name. Use lowercase, hyphens for spaces, descriptive. For the practice exercise in this lesson, use git-practice.

Description — Optional. A one-sentence description that appears under the repo name on GitHub. Worth filling in.

Visibility — Public or Private.

  • Public: anyone can view the repository. Required for free GitHub Pages hosting and expected for portfolio projects.
  • Private: only you (and collaborators you invite) can see it.

The initialization options — choose carefully

Section titled “The initialization options — choose carefully”

This is where most beginners run into trouble. GitHub offers to initialize the repository with files. Whether you should accept depends on whether you already have a local repository.

Initialize this repository with a README — Creates a README.md file and an initial commit. The repo is not empty; it already has history.

Add .gitignore — Creates a .gitignore file appropriate for a chosen language or framework.

Choose a license — Creates a LICENSE file.

Scenario A: You have an existing local repository

Section titled “Scenario A: You have an existing local repository”

Do not check any initialization options. Create the repository empty (no README, no .gitignore, no license).

If you initialize GitHub’s repo with a README but your local repo also has commits, the two repositories have different histories and Git will refuse to push:

error: failed to push some refs to 'github.com/...'
hint: Updates were rejected because the remote contains work that you do not have locally.

An empty GitHub repo has no history, so there is nothing to conflict with when you connect your local repo and push. The next lesson covers exactly how to do this.

Scenario B: You are starting a brand-new project

Section titled “Scenario B: You are starting a brand-new project”

Check the initialization options. Initialize with a README, add a .gitignore appropriate for your project type, add a license if you want one. Then clone the repository to your machine rather than running git init locally.

For the STO project (Module 07), you already have a local repository, so you will use Scenario A — an empty GitHub repository.

GitHub displays a page with instructions for what to do next. The two most useful sections are:

“…or create a new repository on the command line” — Commands for initializing a local repo and connecting it to this GitHub repo. For starting from scratch.

“…or push an existing repository from the command line” — Commands for connecting an existing local repo to this GitHub repo. This is what you will use in the next lesson.

You do not need to memorize these. GitHub shows them every time you create an empty repository.

  1. On GitHub, create a new repository named git-practice.

  2. Set it to Public.

  3. Do not initialize with a README, .gitignore, or license — your local git-practice repo already has commits.

  4. After creating, read the page GitHub shows you. Find the section “push an existing repository from the command line.” Note the two commands shown — you will run them in the next lesson.

  5. Do not close this page — you will need the remote URL in the next lesson.

  • Create a new repository on GitHub with the + icon → “New repository.”
  • Repository name becomes the URL slug. Lowercase, hyphens, descriptive.
  • Public repositories are visible to everyone. Required for portfolio projects and GitHub Pages.
  • If you have an existing local repository: create the GitHub repo empty (no initialization options checked) to avoid history conflicts.
  • If you are starting fresh: initialize on GitHub with a README and clone.
  • After creating an empty repo, GitHub shows you the commands to connect and push your local repository.

The next lesson shows you how to connect your local git-practice repository to the GitHub repository you just created.