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 7Name in the course: Git tools

Use stash, tags, bisect, blame and worktrees

Git has tools for the moments that do not fit the normal flow: put unfinished work aside, mark versions, find the commit that broke something, see who changed a line and why, or work on two branches at the same time.

  • 6 Lessons
  • 3 Commands

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

7.1

Put work aside with stash

git stash saves uncommitted changes and gives you a clean working tree — for example to fix something urgent on another branch.

git stash push -m "half-done NSG rules"
git stash list
stash@{0}: On feature/web: half-done NSG rules
git switch main
git switch feature/web
git stash pop
git stash push -u
git stash drop stash@{0}

-u also stashes untracked files.

Commands in this lesson

7.2

Mark versions with tags

A tag is a fixed name for a commit, usually a version. Annotated tags have a message, an author and a date.

git tag -a v1.0.0 -m "First production release"
git tag
git show v1.0.0
git push origin v1.0.0
git tag -d v0.9.0-test
git push origin --delete v0.9.0-test

Remember

Modules and pipelines often use tags as versions (?ref=v1.0.0). Never move a tag that others use — make a new one.

Commands in this lesson

7.3

Find the bad commit with bisect

git bisect does a binary search through history: you say "good" or "bad" for each commit Git picks, and it finds the first bad one fast.

git bisect start
git bisect bad
git bisect good v1.2.0
git bisect good
git bisect bad
git bisect run ./test.sh
git bisect reset

With git bisect run SCRIPT, Git tests every step itself (exit code 0 = good).

Commands in this lesson

7.4

See who changed a line

git blame shows the last commit for every line — to find why something was changed, not who to blame.

git blame -L 20,40 modules/network/main.tf
git log -S "0.0.0.0/0" --oneline
git log -L 20,30:modules/network/main.tf

git log -S TEXT finds the commits that added or removed a text — great for "when did this rule appear?".

Commands in this lesson

7.5

Work on two branches at once

A worktree is a second working folder for the same repository — no need to stash or clone again.

git worktree add ../infra-hotfix hotfix/dns
cd ../infra-hotfix
git worktree list
git worktree remove ../infra-hotfix

Commands in this lesson

All commands in this chapter