Skip to content
Ameen Abozaid
BEG-046

Version control

  • 8 Lessons
  • 83 min of reading
  • 3 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Repository
  • commits
  • staging
  • branches
  • merges
  • conflicts
  • .gitignore

Learn first

83 min of reading · 3 h of practice (estimate)

Learning outcomes

  1. Initialize a repository, stage changes, and write clear commit messages.
  2. Inspect history and differences with log, status, and diff.
  3. Create, switch, and merge branches, and resolve a merge conflict by hand.
  4. Write a .gitignore that excludes build output and secrets.

Lessons

  1. 01Why version control12 min read
  2. 02Repositories, staging, and commits11 min read
  3. 03History and diffs10 min read
  4. 04Branches10 min read
  5. 05Merging and conflicts10 min read
  6. 06.gitignore10 min read
  7. 07Demo: putting Bank Accounts under Git10 min read
  8. 08Demo: creating and resolving a merge conflict10 min read

Lab and exercises

Lab

BEG-046-LAB1 · Version your work

Outcomes: 1–4 · Time: ~3 h Put the Bank Accounts project under Git with meaningful commits (at least five). Create a feature branch, make conflicting changes on both branches, merge, and resolve the conflict by hand. Add a .gitignore. Acceptance: clean history (clear messages, no target/ or .idea/); conflict resolved correctly.

Exercises (assessment: terminal-only Git task)

IDOutcomeTask
BEG-046-EX011In a new folder, initialize a repo, create Hello.java, stage and commit it with a clear message.
BEG-046-EX021Rewrite these bad messages as good ones: "fix", "stuff", "changes". Use a bug-fix example of your own.
BEG-046-EX032Change a file, then show the difference unstaged and staged. Which two commands did you use?
BEG-046-EX042List the last five commits in one-line form.
BEG-046-EX053Create branch greeting, commit a change, switch back, and merge with no conflict.
BEG-046-EX063Make both branches edit the same line, merge, and resolve the conflict.
BEG-046-EX074Write a .gitignore for a Java project; prove target/ stays untracked.
Show solutions
  • EX01 git init, git add Hello.java, git commit -m "Add Hello program".
  • EX02 e.g. "Fix negative balance after withdraw", "Add Account class with deposit", "Rename amount to balance".
  • EX03 git diff (unstaged) and git diff --staged.
  • EX04 git log --oneline -5.
  • EX05 git switch -c greeting, commit, git switch main, git merge greeting (fast-forward).
  • EX06 After git merge, open the file, keep the intended text, delete the markers, git add file, git commit.
  • EX07 target/, *.class, .idea/, .env; git status does not list them.

Quiz

Outcomes: O1 init, stage, commit · O2 inspect history · O3 branch and merge · O4 .gitignore.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1Which command turns a folder into a Git repository?O1
  2. 2Staging means:O1
  3. 3Which message is best?O1
  4. 4Which command lists past commits?O2
  5. 5Which shows changes already staged?O2
  6. 6Which creates and switches to a new branch?O3
  7. 7A merge conflict happens when:O3
  8. 8After fixing conflict text in a file you must:O3
  9. 9Which belongs in .gitignore?O4
  10. 10A password was committed by mistake. Best response:O4

Practical part

Terminal-only Git task: init, commit, branch, conflict, merge, .gitignore (EX01–EX07 and the lab). Pass: at least 8 of 10 quiz questions and a clean history with the conflict resolved.

Common mistakes

"fix" commit messages; committing target/ or .idea/; committing passwords.

Assessment

Terminal-only Git task.

Career relevance

Daily tool; team workflows in JNR-053.

Type to search levels, phases, modules and lessons.