AI Hints
CI/CD with GitHub Actions · Lesson 7 of 138

Git in Two Minutes

Commits and history.

⏱ 2 min read▶ Video at 7:03🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

CI/CD starts with git. Every pipeline run is triggered by something happening in a git repository, usually a new commit. So let's do a two minute refresher on the git commands this course uses.

Git in Two Minutes
From the video: Git in Two Minutes
  • CI/CD starts with git
  • Commits trigger pipelines
  • A quick refresher

A repository and a commit

Git init turns the shop folder into a repository. Git status shows the files git isn't tracking yet. Git add, with a dot, stages everything, and git commit saves a snapshot, with a message after dash M. Git log, with one line, shows the history.

Terminal
git init
Initialized empty Git repository in /home/sam/shop/.git/
git status --short
?? .gitignore
?? README.md
?? app.py
?? requirements.txt
?? test_app.py
git add .
git commit -qm "First version of the shop"
git log --oneline
7418016 First version of the shop

Changing and committing again

Let's improve the project. Echo adds a line to the readme. Git diff shows exactly what changed. Then we commit again, and the log now shows two commits, the newest at the top. Each one has a short i d, called a hash. Pipelines report results for a specific commit hash.

Terminal
echo "Run the tests with pytest." >> README.md
git diff
diff --git a/README.md b/README.md
index a6f607f..9c6ac49 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,3 @@
 # Shop
 A tiny shop library.
+Run the tests with pytest.
git commit -am "Explain how to run the tests"
[main 079d121] Explain how to run the tests
 1 file changed, 1 insertion(+)
git log --oneline
079d121 Explain how to run the tests
7418016 First version of the shop

Summary

Git init, add, commit, and log are the basics. Every commit has a hash, and pipelines run against those commits. Next, branches and pull requests.

Key takeaways
  • git add + commit
  • git log --oneline
  • Every commit has a hash
Next up: Branches and Pull Requests — how teams work