Objective. Students configure a .gitignore file to exclude sensitive and build files, verify that tracked sensitive data can be removed from history using git filter-repo or BFG, and confirm SSH authentication is used for all remote operations.
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.
A Git repository stores every version of every file you have ever committed. That history is a powerful feature for development, but it becomes a serious liability the moment a secret — an API key, a database password, a private token — is accidentally committed. Even if you delete the file in a later commit, the secret remains readable in the older commits. Anyone who clones or forks the repository can retrieve it. This lesson teaches you three interlocking defenses: preventing secrets from entering the repository with `.gitignore`, removing secrets that have already been committed, and securing your connection to remote services with SSH keys.
A `.gitignore` file tells Git which files and directories to leave completely untracked. Git will never stage or commit a path that matches an active ignore rule, and it will not show those paths in `git status` output.
A well-structured `.gitignore` for a web project covers four categories:
The free tool at gitignore.io (also reachable as `toptal.com/developers/gitignore`) lets you type in your stack — for example `python,php,windows,macos,vscode` — and it generates a ready-to-use file. Always commit `.gitignore` to the repository so every collaborator shares the same rules.
Adding a path to `.gitignore` only prevents future tracking. If a file is already tracked, Git continues to track it even after you add the ignore rule. You must run `git rm --cached <file>` to untrack it without deleting it from your working directory.
If a secret has been committed — even once, even many commits ago — you must rewrite history to remove it. Two tools are widely used:
After running either tool, every affected commit gets a new SHA hash. You must force-push (`git push --force` or `git push --force-with-lease`) to replace the remote history. Coordinate with your team first — anyone who has cloned the repository must re-clone or carefully rebase, because their local history is now diverged.
Always revoke and rotate the exposed credential immediately, even before you finish cleaning the history. Assume the secret was seen the moment it was pushed.
To verify that a file is completely gone from all history, run:
```
git log --all --full-history -- .env
```
If the command returns no output, the file does not appear in any commit on any branch or tag.
Git supports two transport protocols for remote operations: HTTPS and SSH. HTTPS requires you to authenticate with a username and token (or password) on every operation unless you use a credential helper. SSH uses a public/private key pair: your private key stays on your machine; the matching public key is uploaded to GitHub (or another host). Once configured, SSH operations require no password entry and are not vulnerable to credential-harvesting attacks that target passwords typed into prompts.
Check your remote URL with:
```
git remote -v
```
An SSH remote looks like `git@github.com:username/repo.git`. An HTTPS remote looks like `https://github.com/username/repo.git`. You can switch a remote from HTTPS to SSH with `git remote set-url origin git@github.com:username/repo.git`.
Generate a new SSH key pair with:
```
ssh-keygen -t ed25519 -C "your_email@example.com"
```
The `ed25519` algorithm is the current best practice. Accept the default file location or specify one, and set a strong passphrase when prompted — the passphrase protects your private key if your machine is compromised.
Copy the contents of the `.pub` file (the public key) to GitHub → Settings → SSH and GPG keys → New SSH key. Never share the private key file.
Test the connection with:
```
ssh -T git@github.com
```
A successful response reads: `Hi username! You've successfully authenticated...`
After adding a new key, remove the old key from GitHub settings so it can no longer be used.
Answer each question, then check it. Nothing is recorded; this is your own practice.
A free tech program — complimentary, as our commitment to get America working. Help us build VoTechWorks. Tell us what works, what doesn’t, and what you want to learn.