🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Cybersecurity › Scripting for Cybersecurity › Lesson 9
TEC-CYBE44-05 · Lesson 9 · 10 clock hours · demo

Version Control with Git: Tracking and Collaborating on Security Scripts

Objective. Students use Git from the command line to initialize repositories, commit changes, create branches, and resolve a simulated merge conflict in a security-script project.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

Why Version Control Matters in Cybersecurity

Security professionals write scripts constantly — for log parsing, vulnerability scanning, incident response automation, and more. Without a disciplined way to track changes, a single bad edit can break a critical tool at the worst possible moment. Version control lets you record every change, understand why it was made, roll back to a working state, and collaborate safely with teammates. Git is the industry-standard distributed version control system used across nearly every professional environment.

Core Git Concepts

Repository (repo): A directory that Git monitors. It contains your files and a hidden `.git` folder that stores the full history of every change.

Commit: A snapshot of your files at a specific moment. Every commit has a unique hash, an author, a timestamp, and a message explaining what changed and why.

Branch: An independent line of development. The default branch is usually called `main`. You create branches to develop new features or fixes without disturbing working code.

Merge: Combining changes from one branch into another. When two branches modify the same part of a file differently, Git cannot decide automatically — this is a merge conflict that you must resolve manually.

Remote: A version of the repository hosted elsewhere (for example, on GitHub or an internal server). You push local commits to a remote and pull others' commits down.

Essential Git Commands

| Command | What it does |

|---|---|

| `git init` | Creates a new local repository in the current directory |

| `git status` | Shows which files are modified, staged, or untracked |

| `git add <file>` | Stages a file for the next commit |

| `git commit -m "message"` | Records staged changes with a descriptive message |

| `git log --oneline` | Displays commit history in a compact format |

| `git branch <name>` | Creates a new branch |

| `git checkout <name>` | Switches to a branch (or use `git switch <name>`) |

| `git merge <name>` | Merges the named branch into the current branch |

| `git diff` | Shows line-by-line differences not yet staged |

Always run `git status` before you commit. It prevents you from accidentally staging files that should stay out of the repo.

Protecting Secrets with .gitignore

One of the most serious mistakes in security scripting is committing credentials, API keys, or passwords into a repository — even a private one. Once a secret enters Git history it is extremely difficult to remove completely, and if the repo is ever made public or cloned carelessly, the secret is exposed.

A `.gitignore` file tells Git to ignore specific files or patterns. Place it in the root of your repository. Example entries for a security-script project:

```

secrets.env

*.env

config.local.py

.DS_Store

__pycache__/

*.pyc

```

Create `.gitignore` before your first commit so the ignored files are never tracked. If you accidentally commit a secret, treat the credential as compromised immediately — rotate it regardless of any Git history cleanup you attempt.

Writing Good Commit Messages

A commit message is documentation for your future self and your teammates. A weak message like `fix stuff` tells no one anything useful. A strong message explains what changed and why:

Using the imperative mood (`Add`, `Fix`, `Refactor`) is the widely accepted convention in professional projects.

Branching and Merging Workflow

A common workflow for a security script project:

1. Work on `main` for stable, tested code.

2. Create a feature branch: `git branch add-alerting` then `git checkout add-alerting`.

3. Make commits on the feature branch.

4. When the feature is tested, merge it back: `git checkout main` then `git merge add-alerting`.

Resolving Merge Conflicts

When a merge conflict occurs, Git marks the affected file like this:

```

<<<<<<< HEAD

print("Alert: threshold exceeded")

=======

print("WARNING: limit reached")

>>>>>>> add-alerting

```

The section between `<<<<<<< HEAD` and `=======` is what the current branch has. The section between `=======` and `>>>>>>>` is what the incoming branch has. You decide which version is correct (or combine them), delete all the marker lines, save the file, then run `git add <file>` and `git commit` to complete the merge.

Always test the resolved file before committing the fix. In a security context, a broken script may mean missed alerts or a failed automated response.

Lab Safety and Best Practices

Key terms8

RepositoryA directory tracked by Git that stores all project files and the complete history of every change made to them.
CommitA saved snapshot of staged changes in a repository, identified by a unique hash and accompanied by a descriptive message.
BranchAn independent line of development within a repository that allows changes to be made without affecting other branches.
Merge conflictA situation where two branches have made different changes to the same part of a file and Git cannot automatically decide which version to keep.
.gitignoreA file placed in a repository's root that lists filenames and patterns Git should not track, commonly used to exclude files containing credentials or API keys.
Staging areaAn intermediate zone where changes are gathered using git add before they are permanently recorded with git commit.
RemoteA copy of a repository hosted on another machine or service, used to share code and collaborate with others by pushing and pulling commits.
git logA Git command that displays the history of commits in a repository, including hashes, authors, dates, and messages.
In class: Instructor-led walkthrough of git init, git add, git commit, git log, git branch, git checkout, and git merge using a sample script repository on the projector screen. · Hands-on exercise: each student creates a local Git repository for their course scripts, writes a .gitignore that excludes files containing API keys (e.g., secrets.env), and makes at least five meaningful commits with descriptive messages. · Simulated collaboration: students are given a repository with a deliberate merge conflict in a Python script and must resolve it manually using a text editor, then verify the resolved file runs correctly before committing the fix.
Materials: Ubuntu VM, Git documentation (git-scm.com), course lab guide chapter 9
Check: Student repository has at least five commits with non-trivial commit messages, a correct .gitignore, and the resolved-conflict commit produces a runnable script confirmed by instructor; all three required to pass.

Practice check6

Answer each question, then check it. Nothing is recorded; this is your own practice.

Security Operations
1. A security analyst accidentally commits a file named `secrets.env` containing an AWS API key to a local Git repository. What is the MOST important immediate action?
Security Operations
2. Which Git command stages all modified files in the current directory so they are included in the next commit?
Security Operations
3. A team member opens a Python script after a merge and sees lines containing `<<<<<<<`, `=======`, and `>>>>>>>`. What do these markers indicate?
Security Operations
4. A cybersecurity student wants to develop a new alerting feature without risking the stable main branch. What is the correct sequence of Git commands?
Security Operations
5. After resolving a merge conflict in a Python incident-response script, what should the analyst do BEFORE running git commit?
Governance, Risk, and Compliance
6. From a security governance perspective, why is maintaining detailed Git commit history valuable for a security team's scripts?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.