Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
GitHub Essentials  ›  Lesson

Creating a Repository on GitHub

Creating Repositories 12 minTo publish an existing local repository, create an empty GitHub repository and push to it; to start fresh, create it with a README and clone it.

Creating a Repository on GitHub

Throughout the Remotes section, Asha's recipe-box already had a home at github.com/asha-dev/recipe-box. This lesson shows how that home was made, and the one checkbox choice that decides whether the first push goes smoothly.

The rule

Local project already? Create the GitHub repository empty, then push.

Click + in the top bar and choose New repository. The form asks for:

  • Owner: your account, or an organisation you belong to.
  • Repository name: short, lower-case, hyphenated, such as recipe-box.
  • Description: one line that appears on the repository page.
  • Visibility: public or private (the next lesson covers the choice).
  • Initialise options: add a README, add a .gitignore from a template, choose a licence.

The initialise options decide which route you are on.

Route 1, starting fresh on GitHub. Tick "Add a README" and choose a .gitignore template. GitHub creates a first commit. Then clone it to your machine and work from there.

Route 2, pushing an existing local repository, which was Asha's case. Leave all the initialise options off, so the GitHub repository is completely empty. GitHub then shows the commands to connect it:

git remote add origin https://github.com/asha-dev/recipe-box.git
git branch -M main
git push -u origin main

git branch -M main renames the current branch to main, which is harmless if it is already called that. After the push, refresh the page: the files, the README and every commit from your laptop are there.

Why keep it empty? If GitHub creates its own first commit and you also have local commits, the two histories share no starting point. Your push is rejected, and combining them needs extra steps that beginners should not have to face on day one.

A few habits help from the start: always include a README.md (in your local project, for Route 2), commit a .gitignore early, and choose a licence if you want others to reuse your work.

The shortcut

Ask "Where do my first commits live?" On GitHub → Route 1, tick README and clone. On my laptop → Route 2, tick nothing and push.

Giving recipe-box a homeStep 1 of 4
  1. Where are the commits?

    On Asha's laptop: several commits, from "Add chai and pancake recipes" onwards. So this is Route 2.

The trap is ticking "Add a README" out of habit when you already have local commits, then being surprised by a rejected push.

Drills

Answer fast — trust the rule.

quick drill

Asha has a local repository with commits. How should she create the GitHub repository?

quick drill

Which command sends Asha's main to the new repository and sets it as upstream?

quick drill

Ravi is starting a brand-new project with nothing on his laptop. What is the simplest route?

quick drill

Asha ticked "Add a README" on GitHub and also has local commits. Why is her first push rejected?

Remember

  • Local project already? Create the GitHub repository empty, then push.
  • Where do my first commits live? GitHub → tick README and clone; laptop → tick nothing and push.
  • Always have a README and a .gitignore; add a licence if others may reuse the work.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainPublish recipe-box

Asha has recipe-box on her laptop with several commits and no remote. Explain how she creates its GitHub repository and publishes it, including which form options she leaves off and why.