Create the Store's GitHub Repository

The site runs, the check passes, and the README’s To do section has one new paragraph instead of a list. It says the work now arrives as issues on the project’s GitHub repository, and a commit that finishes one closes it with Closes # and the issue’s number. That plan has a gap, though, because the project doesn’t have a GitHub repository yet. All twenty-two commits live in one folder on one laptop, one spilled coffee away from being gone.

In this lesson, you’ll give the store’s site a home on GitHub. You’ll create an empty public repository there, connect your local repository to it with a short name, and see the check report pick it up. Start with the question of what GitHub will hold that your laptop doesn’t already have.

Decide What Lives on GitHub

Before you click anything, it helps to know what you’re about to create, because a GitHub repository and the repository on your laptop aren’t quite the same thing. In the first course, you met GitHub as a hosting service, a website that stores another copy of a repository so that other people, or your other computers, can reach it. GitLab and Bitbucket do the same job, and everything in this lesson works much the same way there.

A hosting service adds a few things that a folder on your laptop can’t offer:

  • A copy that’s always online, so the store’s back-office computer can get the project later in this course, even when your laptop is closed

  • A web view of the files and the history, where you can read any commit in the browser

  • Accounts and permissions, which decide who can see the repository and who can change it

  • Tools for working together, such as the issues that the README now talks about

The first two are Git’s own data, shown on a website. The last two exist only on GitHub, and you’ll notice the difference as soon as you work from more than one place.

Everything Git tracks travels with the commits you push, which means the files and the whole history that leads to them. In this course, you’ll push main, so GitHub gets main and every commit before it, while a branch you never push stays on your laptop only.

Issues, the repository’s visibility and the list of people who can change it are GitHub’s own records about the repository. They’re stored on GitHub’s servers and never end up in your .git folder.

So when you set up a second computer from GitHub later in this course, it gets every commit you pushed, but none of the issues. And if you ever delete the repository on GitHub, your commits will still be safe on your laptop, while its issues will be gone.

If that split between Git and GitHub still feels blurry, then ask the mentor about it. The button below opens a chat with the question filled in and the paragraph about what travels with a push attached:

With that picture in mind, you can create the GitHub side and decide which of GitHub’s own settings the store’s repository needs.

Create an Empty Public Repository

Your history needs somewhere to go on GitHub, and the form for a new repository has a few choices that matter for the rest of this path. Sign in to GitHub, or sign up for a free account if you don’t have one yet, and then follow these steps:

  1. Click the + menu at the top right of any GitHub page and choose New repository.

  2. Type generic-grocery as the Repository name. The description is optional, and the first sentence of the README works well there.

  3. Choose Public as the visibility.

  4. Leave the options for a README, a .gitignore file, and a license as they are, all turned off.

  5. Click Create repository.

A public repository means that anyone can read its files and its whole history, though only you can change them. That’s a good fit for a store’s website, which is public anyway, and it can be a project you show to an employer.

It’s also the practical choice, because on a free account, GitHub offers GitHub Pages for hosting websites and the rules that protect a branch only for public repositories. You’ll use both later on the path.

Going public is also the moment your safety habits from the first two courses pay off. If you followed them, then notes.txt with the Wi-Fi password and .env with the Generic Curbside key were both ignored before they could be committed, so neither is anywhere in the history you’re about to publish.

Ignoring a file only keeps it out of future commits, though, so check the history itself. git log --oneline followed by -- and filenames lists only the commits that touched those files:

Language: Shell
$ git log --oneline -- notes.txt .env

Git doesn’t print anything, so no commit ever held either file. If it lists a commit in your own repository, then don’t push anything yet, and ask the mentor how to remove the file from the history first.

The last choice, leaving the README, .gitignore, and license off, is why this repository is called empty. You might wonder why you’d skip a README when every good project has one.

Your project already has a README.md, a .gitignore, and twenty-two commits of history. If GitHub adds a README of its own, it creates a first commit on GitHub that your laptop’s history doesn’t contain, so the two histories have nothing in common and Git rejects your first push. When you already have a local repository, you create the hosted one empty and let your push bring the files.

If you already ticked one of those boxes, then delete the repository in the Danger Zone at the bottom of its Settings page and create it again with all three turned off. On a team, you’d also invite people under Settings → Collaborators so they can push. Here, your “someone else” is your own second computer, so you’re the only collaborator you need.

Point Git at the Repository

After you click Create repository, GitHub shows the empty repository’s Quick setup page. Make sure HTTPS is selected next to the address, not SSH, because you’ll sign in over HTTPS in the next lesson. Then copy the address with the copy button. It has your GitHub login in it, and in this course’s examples the made-up login generic-grocery-dev stands in for yours:

Language: Text
https://github.com/generic-grocery-dev/generic-grocery.git

The same page lists commands for pushing an existing repository. You’ll run them in this lesson and the next one, learning what each does as you type it. First, check which other copies your local repository knows about. In the terminal in your generic-grocery folder, run git remote -v:

Language: Shell
$ git remote -v

It doesn’t print anything. Your laptop’s repository doesn’t know about any other copy yet, so a git push wouldn’t know where to send your commits. A remote is a short name that your repository keeps for another copy’s address. You add one with git remote add, followed by the name and the URL you copied:

Language: Shell
$ git remote add origin https://github.com/generic-grocery-dev/generic-grocery.git
$ git remote -v
origin  https://github.com/generic-grocery-dev/generic-grocery.git (fetch)
origin  https://github.com/generic-grocery-dev/generic-grocery.git (push)

Paste your own URL instead of the example’s, so the address ends in your login and generic-grocery.git. Now git remote -v lists the remote twice, with (fetch) for getting commits from GitHub and (push) for sending commits there. Both use the same address. Adding a remote doesn’t contact GitHub at all, because it only writes the name and the URL into your repository’s settings.

The name origin is a convention for the main copy you work with. A few Git commands fall back to origin when you don’t name a remote, but it’s still only a name for an address and gives that copy no special authority. To see that for yourself, rename it to github, look at the list, and rename it back:

Language: Shell
$ git remote rename origin github
$ git remote -v
github  https://github.com/generic-grocery-dev/generic-grocery.git (fetch)
github  https://github.com/generic-grocery-dev/generic-grocery.git (push)
$ git remote rename github origin

Renaming changes only the name your laptop uses. GitHub doesn’t store the name you give the remote, so the rename doesn’t change anything there. Keep origin, though, because the rest of this course, the check script, and most tutorials use that name. If you ever need to drop a remote entirely, then git remote remove followed by its name does it. Git’s documentation for git remote lists every subcommand, though these are the ones you’ll use.

The check script looks for a remote called origin, so run npm run check to see what it makes of the new connection:

Language: Shell
$ npm run check
npm notice run [email protected] check
npm notice run node scripts/check.js
Checking the Git repository in /Users/martin/projects/generic-grocery

✔ Git is installed (git version 2.43.0).
✔ The project folder is a Git repository.
✔ Your commits are labeled Martin Breuss <[email protected]>.
✔ .gitignore keeps notes.txt out of the repository.
✔ .gitignore keeps .DS_Store out of the repository.
✔ The history has 22 commit(s).
✔ npm is version 12 or later.
✔ You're on the main branch.
✔ package.json has "type": "module".
✔ package.json has a "check" script, so npm run check runs this report.
✔ .gitignore keeps node_modules/ out of the repository.
✔ package-lock.json is tracked, so every copy installs the same package versions.
✔ .gitignore keeps .env out of the repository.
✔ .env.example is committed, with a placeholder instead of the key.
✔ No tracked file holds a Generic Curbside secret key (curb_sec_...).
✔ origin is your GitHub repository, generic-grocery-dev/generic-grocery.
✘ main has no upstream branch, so git push and git pull don't know where to go.
  Next step: git push -u origin main, once.
✔ No file has leftover conflict markers.
✔ GitHub has your public repository generic-grocery-dev/generic-grocery.
! GitHub didn't say where its main is (status 409).
  Next step: wait a few minutes, then run the check again.
! None of this week's issues are on GitHub yet.
  Next step: create them from the lesson, with their titles exactly as given.
✔ Everything is committed.

1 check(s) failed.

Your report shows your own name, folder, and login. Since the repository now has an origin, the script runs its GitHub checks too, and the new lines tell you where things stand:

  • origin is your GitHub repository confirms that the URL you added points at GitHub, with your login and the repository’s name.

  • main has no upstream branch is the one failing check, and it’s expected. Your main branch isn’t connected to a branch on GitHub yet, and the next step it suggests, git push -u origin main, is exactly what you’ll run next.

  • GitHub has your public repository means that GitHub found the repository and that anyone can read it, as you chose.

  • GitHub didn’t say where its main is (status 409) is GitHub’s way of saying that the repository is empty. It has no commits, so it has no main branch to report. Waiting won’t change that, but your first push will.

  • None of this week’s issues are on GitHub yet is right too. You’ll file the week’s work as issues once the code is on GitHub.

If a line in your own report doesn’t match these, or you’d like to check that you read the origin and upstream lines right, then ask the mentor. Use the button below to start a chat with the question prefilled and those two report lines attached. Paste your own report there to talk through what each line says about your setup:

Before you push, make sure you can explain what you’ve set up. Answer these questions, and then open the answers:

  1. You set up the store’s site on the back-office computer from GitHub. Which of the commits on main, the .gitignore file, and the repository’s issues does that copy get, and which stay behind?
  2. You rename your remote with git remote rename origin store. What changes on GitHub, and what does git remote -v show afterward?
  3. git remote -v shows https://github.com/generic-grocery-dev/generic-grocey.git, with a letter missing. Which command fixes it without adding a second remote?
  1. The copy gets the commits on main and .gitignore, because you pushed main, and .gitignore is a tracked file in its history. A copy from GitHub has whatever history was pushed there. The issues stay on GitHub, because they’re GitHub’s own records about the repository, not part of the Git history.
  2. Nothing changes on GitHub, because a remote’s name exists only in your local repository. git remote -v lists the same URL twice, for fetch and push, under the name store instead of origin.
  3. Run git remote set-url origin https://github.com/generic-grocery-dev/generic-grocery.git, with your own login, and check it with git remote -v. Running git remote add origin again with a URL fails, because origin already exists.

Your laptop now knows where the store’s repository lives, but GitHub still has an empty repository waiting for its first commit. In the next lesson, you’ll push the site’s whole history with git push -u origin main, and GitHub will ask you to sign in before it accepts anything.

Become a Member to join the conversation.