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.
- 1Install Git
- 2Tell Git who you are
- 3Three preferences worth setting now
- 4Create the repository
- 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:
git --versionIf 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 --versionoffers to install the Xcode Command Line Tools, which include Git. If you use Homebrew,brew install gitgets 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 giton Ubuntu orsudo dnf install giton 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:
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
git config --global init.defaultBranch main
git config --global core.editor "code --wait"
git config --global --listinit.defaultBranch mainnames the first branch of every new repositorymain, which matches what GitHub creates. Without it, Git 2.x still names the first branchmasterand prints a long hint about it.core.editoris 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 --waituses VS Code (the--waitkeeps Git waiting until you close the tab);nanois a simple terminal option.--listprints 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:
mkdir portfolio
cd portfolio
git initInitialized 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:
<!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:
git statusOn 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.
git add index.html
git commit -m "Add home page"[main (root-commit) 3f9c2a1] Add home page
1 file changed, 11 insertions(+)
create mode 100644 index.htmlRead 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 --globalonce per machine foruser.name,user.email,init.defaultBranchandcore.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 initcreates a hidden.gitfolder; that folder is the repository, and deleting it deletes all history.- A commit is two steps,
git addto choose what goes in andgit commit -mto record it with a message.