EduFlow
Git & GitHub
0%

Section 1 · Git's Model

Install, Configure, and Make Your First Commit

16 min3 min readFill in the blanks

Lesson at a glance

Install Git, set your name, email, default branch and editor once, then turn your portfolio folder into a repository and record its first commit.

  1. 1Install Git
  2. 2Tell Git who you are
  3. 3Three preferences worth setting now
  4. 4Create the repository
  5. 5Make the first commit

No video here — just the real thing: a written lesson, runnable examples, a quiz and practice.

Before Git can record anything, it needs two facts about you and a few preferences. You set these once per computer, and they quietly shape every commit you make for years. Ten minutes now saves you from hundreds of commits credited to “unknown” or an address you no longer own.

Install Git

Check whether Git is already there:

Terminal
git --version

If you see something like git version 2.51.0, you’re set; any 2.4x or newer version works for this course. If not:

  • macOS: running git --version offers to install the Xcode Command Line Tools, which include Git. If you use Homebrew, brew install git gets you a newer one.
  • Windows: install Git for Windows from git-scm.com. Keep the defaults; they include Git Bash (a terminal where every command in this course works) and Git Credential Manager, which you’ll use in section 3.
  • Linux: use your package manager, for example sudo apt install git on Ubuntu or sudo dnf install git on Fedora.

Tell Git who you are

Every commit stores an author name and email. Set them globally, meaning for your user account on this machine:

Terminal
git config --global user.name "Maya Okafor"
git config --global user.email "maya.okafor@example.com"

The email matters more than it looks. GitHub decides whose avatar and profile appear next to a commit by matching the email inside it against the addresses on GitHub accounts. If you’d rather not publish your real address, GitHub gives every account a noreply address of the form 12345678+username@users.noreply.github.com (find yours under Settings, then Emails) and you can use that instead.

Three preferences worth setting now

Terminal
git config --global init.defaultBranch main
git config --global core.editor "code --wait"
git config --global --list
  • init.defaultBranch main names the first branch of every new repository main, which matches what GitHub creates. Without it, Git 2.x still names the first branch master and prints a long hint about it.
  • core.editor is the program Git opens when it needs you to write text, such as a commit message. Many installs default to Vim, which surprises people who don’t know it. code --wait uses VS Code (the --wait keeps Git waiting until you close the tab); nano is a simple terminal option.
  • --list prints what you’ve set so you can check for typos.

These go into a plain text file, ~/.gitconfig. A setting without --global, run inside a repository, applies only to that repository and overrides the global one. That’s handy if you want a work email in work repositories and a personal one everywhere else.

Create the repository

Make a folder for your portfolio and turn it into a repository:

Terminal
mkdir portfolio
cd portfolio
git init
Text
Initialized empty Git repository in /Users/maya/portfolio/.git/

That hidden .git folder is the repository: every commit, branch and setting for this project lives inside it. The files you edit sit next to it. Don’t edit anything inside .git by hand, and know that deleting it deletes the history while leaving your current files alone.

Make the first commit

Create index.html with a minimal page:

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Maya Okafor</title>
  </head>
  <body>
    <h1>Maya Okafor</h1>
    <p>Front-end developer in progress.</p>
  </body>
</html>

Now ask Git what it sees:

Terminal
git status
Text
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	index.html

nothing added to commit but untracked files present (use "git add" to track)

Untracked means Git sees the file but has never recorded it. Committing is two steps: choose what goes in, then record it.

Terminal
git add index.html
git commit -m "Add home page"
Text
[main (root-commit) 3f9c2a1] Add home page
 1 file changed, 11 insertions(+)
 create mode 100644 index.html

Read that output: you’re on main, this is the root commit (the first one, with no parent), and its short ID is 3f9c2a1. Yours will differ, because the ID is a hash of the content, your name, the time and the parent. Run git log to see the commit with its full ID, author and date.

Why two steps instead of one? Because the gap between add and commit is where you decide what belongs together. That gap has a name, the staging area, and it’s the subject of the next lesson.

Key takeaways

  • Run git config --global once per machine for user.name, user.email, init.defaultBranch and core.editor; Git stores them in ~/.gitconfig.
  • Your commit email decides which GitHub account a commit is credited to, so use one your account knows, such as the noreply address.
  • git init creates a hidden .git folder; that folder is the repository, and deleting it deletes all history.
  • A commit is two steps, git add to choose what goes in and git commit -m to record it with a message.

Further reading

Check your understanding

4 questions

Question 1 of 4

You set user.email to an old work address. Your commits push fine, but GitHub shows them with a grey, unlinked avatar. Why?

Question 2 of 4

You run git commit with no -m and a full-screen editor you don’t recognise opens. What happened?

Question 3 of 4

You accidentally ran git init in your home folder and now every directory shows up as “untracked”. What is the right fix?

Question 4 of 4

Which command makes every new repository on your machine start on a branch called main?

Practice

Fill in the blanks

Set up and commit the portfolio

Fill in the blanks so that every new repository starts on main, the portfolio folder becomes a repository, and the home page is committed with the message on the command line (no editor).

git config --global user.email "maya.okafor@example.com" git config --global main mkdir portfolio && cd portfolio git git add index.html git commit "Add home page"