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
.gitignorefrom 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 maingit 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.
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.
Asha has a local repository with commits. How should she create the GitHub repository?
Which command sends Asha's main to the new repository and sets it as upstream?
Ravi is starting a brand-new project with nothing on his laptop. What is the simplest route?
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.
