Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Chapter 1Name in the course: Git basics

Track changes with your first repository

Git saves snapshots of a folder. Every snapshot (a commit) has a message, an author and a pointer to the one before — a full history you can search, compare and go back to. This chapter covers setup, the three areas, and the daily commands.

  • 5 Lessons
  • 4 Commands

$ run as a normal user# run as root (or with sudo)

1.1

Set up Git once

Tell Git who you are. These values go into every commit.

git config --global user.name "Hosam Hani"
git config --global user.email "76218642+s0sta@users.noreply.github.com"
git config --global init.defaultBranch main
git config --global pull.rebase true
git config --global core.editor vim
git config --list --show-origin
LevelFileOption
System/etc/gitconfig--system
User~/.gitconfig--global
Repository.git/config(default)

At work

Use GitHub's noreply address in public repositories, so your real email is not in the history.

Commands in this lesson

1.2

Know the three areas

A file moves through three places: the working tree (your files), the staging area (the next commit), the repository (saved commits).

working tree  --git add-->  staging area  --git commit-->  repository (.git)
     ^                                                        |
     +----------------------- git restore / switch -----------+
mkdir infra && cd infra
git init
echo "# Infra" > README.md
git status
git add README.md
git status -s
A  README.md
git commit -m "Add README"

1.3

Make good commits

One commit = one logical change, with a clear message: a short summary line, then (optional) why.

git add main.tf variables.tf
git add -p network.tf
git commit -m "Add web subnet and NSG"
git commit -am "Raise VM size for staging"
git commit --amend -m "Add web subnet, NSG and route table"
OptionMeaning
git add -pChoose parts of a file to stage
git commit -aStage all changed tracked files and commit
--amendReplace the last commit (only before you push it)

Commands in this lesson

1.4

Look at the history

git log shows commits; git show one commit; git diff the changes.

git log --oneline --graph --decorate --all
git log -p -- main.tf
git log --author="Hosam" --since="2 weeks ago"
git show HEAD~1
git diff
git diff --staged
git diff main..feature -- modules/
NameMeans
HEADThe commit you are on
HEAD~1, HEAD~2One / two commits before
abc1234A commit by its short hash
main..featureCommits in feature that are not in main

Commands in this lesson

1.5

Ignore files

.gitignore lists files Git must never track: build output, logs, local settings, and secrets.

.gitignore
*.log
.env
.terraform/
*.tfstate*
__pycache__/
node_modules/
git check-ignore -v .env
git rm --cached .env

Watch out

.gitignore does not remove a file that is already committed. git rm --cached FILE stops tracking it — but it stays in the old history. A committed secret must be rotated (changed), not only deleted.

Commands in this lesson

All commands in this chapter