Frontend Development · Tutorial 10 of 11
Git and GitHub for Beginners: your first repository
By the FUTEAC Team · 16 November 2026 · 12 min read · Beginner
In short
Git tracks every version of your code, and GitHub stores those versions online so you can share them anywhere. Start a repository with git init, save a version with git add and git commit, connect it to GitHub with git remote add origin, and publish it with git push. After that, every change is one commit and one push.
- Git and GitHub are two different things. Git is the tool on your computer that tracks versions. GitHub is the website that stores those versions online. You need both for this tutorial, and neither one replaces the other.
- A commit is a save point with a message. It records exactly what your files looked like at that moment, so you can always go back. Good messages say what changed, so future you can read the history like a diary.
init,add,commit, in that order.git initcreates the repository,git addstages files,git commitsaves the version. Every version you ever save follows the same three steps.- The first push needs
-u. It links your branch to GitHub, and after that a plaingit pushis enough. - This tutorial feeds the HTML & CSS Foundations course (/course/html-css-foundations) and the Git & GitHub (/skill/git-github) skill.
Before you start
What is Git, and what is GitHub?
Every beginner loses work the same way. You change a page, it breaks, and you cannot remember what it looked like before.
Git ends that. It watches a folder and records a snapshot every time you tell it to. Each snapshot is a commit, and you can list them, read them, and go back to any of them. Think of it like the save slots in a video game: each commit is a save point with a label, and you can always reload an earlier one.
GitHub is the shelf where those save files live online. It stores the same snapshots Git made, on GitHub's servers, under your account. That is what turns a project on your laptop into a link you can send to anyone, and it backs your work up: if your laptop dies, the snapshots are still on GitHub.
One opinion, up front: learn these two before you learn any framework. React, Node and every tool after them all assume you can already save versions and push them somewhere. Git is the skill that makes every later skill safer.
How do you install Git and check it works?
On Windows, download the installer from git-scm.com and run it, accepting the defaults. On macOS, use Homebrew (brew install git) or the installer from the same site. On Ubuntu or Debian Linux, run sudo apt install git.
Then check it works. Open a terminal and run:
git --versionIn the test run for this tutorial, on Git 2.43.0, the output was:
git version 2.43.0Your number will probably be newer, and that is fine. Any Git from the last few years works for everything in this tutorial. If the terminal says the command was not found, the install did not finish, so run the installer again before going on.
How do you tell Git who you are?
Every commit carries the name of the person who made it, so Git needs yours once. Run these two commands, with your own name and the email address on your GitHub account:
git config --global user.name "Ayesha Khan"
git config --global user.email "ayesha@example.com"The --global flag means this is set once for your whole computer, not just one project. The email should match your GitHub account, because GitHub uses it to link your commits to your profile.
How do you start a repository?
A repository, usually shortened to repo, is a folder Git is watching. Make a folder for your first page and move into it. The page below is the same small page from the Semantic HTML tutorial, so reuse it if you still have it:
mkdir my-first-page
cd my-first-page<h1>My first page</h1>
<p>Hello, GitHub.</p>Save that as index.html inside the folder. Now turn the folder into a repository:
git initThe test run output was:
Initialized empty Git repository in /home/ayesha/my-first-page/.git/The path will show your own folder instead, and that is expected. Git also prints a few hint lines saying the default branch is called master and that the name can be changed. GitHub uses main as the default branch name, so you will rename yours to main in section 7, just before the first push. Nothing is tracked yet, though. git init only creates the empty repository. The next step fills it.
How do you save your first version?
Saving a version has two moves. First, git add stages files, which means marking them for the next snapshot. Then git commit takes the snapshot. Check what Git sees before you stage:
git status --shortThe output is one line:
?? index.htmlThe ?? means the file is untracked: Git sees it but has no snapshot of it yet. Stage it and commit it:
git add index.html
git commit -m "Add first page"The -m flag carries the commit message. In the test run, the output was:
[master (root-commit) 4135aa8] Add first page
1 file changed, 2 insertions(+)
create mode 100644 index.htmlYour commit hash, the 4135aa8 part, will be different, and that is normal. A hash is just the snapshot's ID number. The rest reads plainly: one file changed, two lines added, and the file was created. Now check the state of things:
git status
git log --onelinegit status reports On branch master and nothing to commit, working tree clean, which is Git's way of saying every file is saved. git log --oneline prints the history, one line per commit:
4135aa8 Add first pageYou have one snapshot. That is the whole pattern, and you will repeat it for the rest of your career: change files, git add, git commit, and the history grows one line at a time.
How do you put it on GitHub?
Your snapshots live only on your computer so far. To publish them, create an empty repository on GitHub, then point your local repo at it.
First, on github.com, click the + menu at the top right and choose New repository. Name it my-first-page. Leave the "Add a README file" box unticked. That matters: if GitHub creates a README, the remote repository has a commit your local one does not, and your first push will be rejected (the exact error is in the mistakes section below). Choose Public, then click Create repository.
GitHub then shows setup commands. You only need the two lines under "push an existing repository from the command line". First, rename your branch to main, since GitHub uses main and your repository still calls it master. Then point your local repo at GitHub, with your own username in place of ayesha:
git branch -M main
git remote add origin https://github.com/ayesha/my-first-page.git
git push -u origin maingit remote add origin tells Git where GitHub lives for this project, and origin is just the nickname Git uses for that address. git push -u origin main uploads your snapshots and, because of the -u, links your local main branch to the one on GitHub.
If you forget the -u on the first push, Git stops you with the exact error from the test run:
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin main
To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.The fix is right there in the message: run the command again with -u, or with --set-upstream. With -u included, the test run output was:
To https://github.com/ayesha/my-first-page.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.The middle line is the one to look for: your main branch now exists on GitHub. Open github.com/ayesha/my-first-page in a browser and you will see index.html there, with the commit message "Add first page" beside it.
How do you save the next change?
It is the same three commands as before. Open index.html, add a second line, and save:
<h1>My first page</h1>
<p>Hello, GitHub.</p>
<p>Second line.</p>Then stage, commit, and push. Notice the push has no -u this time, because the link was set on the first push:
git add index.html
git commit -m "Add second line"
git pushIn the test run, the push output was:
To https://github.com/ayesha/my-first-page.git
4135aa8..13a37eb main -> mainYour hashes will differ, but the shape is the same: the range 4135aa8..13a37eb says which commits travelled, and main -> main says where they went. Refresh the GitHub page and the new line is there. That loop, change, add, commit, push, is the daily rhythm of working with Git.
What does .gitignore do?
Some files should never be saved: scratch notes, passwords, and files a tool generates. A file called .gitignore lists them, one pattern per line, and Git skips anything that matches.
In the test run, a file called notes.txt was listed in .gitignore like this:
notes.txtAfter that, git status --short showed only the .gitignore file itself as untracked:
?? .gitignorenotes.txt had vanished from Git's view entirely, even though the file was still sitting in the folder. Add .gitignore itself to the repository with git add .gitignore, so everyone who clones the project ignores the same files. The rule of thumb is simple: if a file holds a secret, or a tool can rebuild it, ignore it.
Putting it together: publish your portfolio page
You already have the page for this. The Frontend Developer roadmap's first project, in Weeks 1–3, is a personal portfolio website, and the HTML & CSS Foundations course ends its layout module with the lesson "Reading: Publishing Your Page with GitHub Pages". Take that portfolio folder and run the same steps on it: git init, git branch -M main, git add ., git commit -m "Add portfolio website", create the empty repository on GitHub, git remote add origin, and git push -u origin main.
Note the git add . there: the dot stages everything in the folder at once, which is what you want for a finished project. The repository URL becomes the link you put on your CV and send to employers. That is the honest point of this tutorial: a public GitHub profile with real projects in it is the portfolio the roadmap keeps promising, and this is how the first one gets there.
Try it yourself
Make a second repository, this time for a page about yourself. Create the folder, write an index.html about yourself, then git init, git branch -M main, git add index.html, git commit -m "Add about page", create the empty repository on GitHub without a README, and git push -u origin main. Then change one sentence on the page, commit it with a clear message, and push again with a plain git push. If the push fails, read the error first: the two errors in this tutorial cover most first-week failures.
Common mistakes
- Committing before telling Git who you are. The commit fails with
Author identity unknown. Run the twogit config --globalcommands and commit again. - Pushing without
-uthe first time. Git answersfatal: The current branch main has no upstream branch. Run the push again with-u origin main. - Ticking "Add a README file" when creating the GitHub repository. The remote then has a commit you do not have, and the push is rejected with
! [rejected] main -> main (non-fast-forward)anderror: failed to push some refs. Fix it withgit pull origin main --allow-unrelated-histories --no-rebase, which merges the README commit into your history, and then push again, or delete the GitHub repository and create it empty. - Running Git commands in the wrong folder.
git addoutside a repository fails withfatal: not a git repository. Check you are inside the project folder withpwdbefore you run anything. - Committing the wrong file. Staged the wrong file? Unstage it with
git restore --staged <file>, tested in this tutorial's run: the file goes back to untracked. That works once your repository has a first commit; before the very first commit, usegit rm --cached <file>instead. If the file is already in a commit, remove it withgit rm --cached <file>and rewrite the commit withgit commit --amend. To fix the last commit message,git commit --amend -m "Better message"rewrites it, also tested here. - Committing secrets or generated files. Passwords and API keys do not belong in a repository. If one slips in, add it to
.gitignore, remove it withgit rm --cached <file>, and commit again. A public repository is public, so check before the first push, not after.
Frequently asked questions
What is the difference between Git and GitHub?
Git is the version-tracking tool on your computer, and it works fully offline. GitHub is a website that hosts Git repositories online, so you can share them and open them from any computer. You install Git; you sign up for GitHub.
Do I need GitHub to use Git?
No. Everything up to the push step works without any account, and many developers use Git only on their own machines. GitHub adds sharing, backup, and a public profile, which is why this tutorial uses it, but the version tracking is all Git.
What should I write in a commit message?
Say what changed, in plain words, starting with a verb: "Add contact page", "Fix broken navigation link", "Update project description". One clear sentence beats a paragraph.
I committed the wrong file. How do I undo it?
If you staged the wrong file but have not committed it yet, unstage it with git restore --staged <file>. If it is already in your last commit and you have not pushed, remove it with git rm --cached <file> and rewrite the commit with git commit --amend. To fix only the last commit message, git commit --amend -m "Better message" rewrites it. Each of these was tested in this tutorial's run. If you already pushed, do not rewrite history: make a new commit that fixes the mistake instead.
What does git status tell me, exactly?
Which branch you are on, which files changed since the last commit, and which are staged for the next one. Run it whenever you feel unsure. It never changes anything, it only reports.
Follow the Frontend Developer Roadmap
Build modern, responsive websites and web apps with HTML, CSS, JavaScript and React. Free, step by step, at your pace.
View the Roadmap