How to Publish a Tech Portfolio and GitHub Profile Without Leaking Secrets or Client Data
A public GitHub portfolio can leak API keys and client data in history, not just in the latest files. Here is how official GitHub, NCSC, and UK government guidance say to publish work safely.
Why a portfolio can leak more than a typo
A public GitHub profile is often the first thing a hiring manager opens. It is also a common place for API keys, access tokens, private keys, customer records, and internal URLs to land by accident, in a commit that still sits in history after you delete the file on the main branch.
GitHub's official documentation is direct about the risk. When credentials are committed as hardcoded secrets, they become targets for unauthorized use. Secret scanning is designed to find those credentials in Git history on all branches, and GitHub also scans issue and pull-request titles, descriptions and comments, discussions, wikis, and secret gists. On public repositories, that scanning runs automatically at no charge. Push protection is a related control: instead of only alerting you after a leak, it can block a push that contains a supported secret before the secret reaches the repository.
Official government guidance makes the same point from the other direction. The UK National Cyber Security Centre tells developers to keep secret credentials logically separate from source code, to use a careful injection process, and to add scanning of repositories for secret keys. UK government guidance on coding in the open says that if you accidentally publish a secret, you must revoke it and provision new keys immediately, and you must assume the secret is compromised no matter how quickly you delete it, because attackers use automated scanning. Those rules apply to a student project and to a contractor's portfolio in the same way they apply to a public service codebase.
Key facts at a glance
- Do not commit API keys, passwords, tokens, or private keys to Git, in a public or a private repository.
- GitHub can block many supported secrets at push time, and it can alert on secrets already in a public repository.
- If a secret is published, revoke and replace it first. Cleaning the file out of the latest commit is not enough, and rewriting history has serious side effects.
- Client data, unpublished product code, and credentials belong outside the portfolio, even if the repository is only a demo.
- Turn on two-factor authentication for the account that owns the repository, and review every change before it lands on the default branch.
Who this is for
This guide is for people who want to show real work: students, career changers, contractors, and engineers assembling a public portfolio or a personal GitHub profile. It is not a complete enterprise security program, and it is not permission to post a former employer's code.
Step 1. Decide what the public repo is allowed to contain
Make a short written list before you click public.
Allowed, if you have the right to publish it: your own code, screenshots you created, architecture notes that do not reveal non-public systems, and a README that explains how a recruiter can run a demo with dummy data.
Not allowed: live API keys, personal access tokens, cloud access keys, database connection strings, private SSH keys, env files with real values, customer or classmate personal data, medical or financial records, credentials for a school or employer account, and source that you do not own. The UK cyber centre also notes that some code is a poor fit for a public repository because it would help an attacker, for example code used to detect fraud or compromise. If your best work is in that category, describe the problem and your role in the README and keep the detection logic closed.
If a project needed a third-party API, the public repo should contain a template such as an env.example file with blank or clearly fake values, plus instructions to create keys in the visitor's own account. It should not contain your key.
Step 2. Keep secrets out of the tree, then keep them out of the commit
Store real secrets outside the repository. A local env file that is listed in gitignore is the usual pattern for a personal project. Confirm the ignore file is in place before the first commit, not after you have already staged the secret file.
Before you push, search your working copy and your staged changes for obvious secret names and values: API_KEY, BEGIN PRIVATE KEY, cloud access-key prefixes, GitHub and chat-token prefixes, connection URLs, and anything that looks like a password. Also look in notebooks, screenshots, test fixtures, and CI configuration. A key pasted into a README just for the demo is still a published secret.
On GitHub, review push protection for your own account. Official documentation says you can manage Push protection for yourself under Settings, then Code security. When push protection detects a potential secret, it blocks the push and explains why. You then remove the secret from the commits you are trying to push and try again. Official material describes several classes of secrets this can catch, including partner patterns for supported providers, generic patterns such as private keys and connection strings when those patterns are enabled, and custom patterns you define. Do not treat a successful push as proof that no secret was present; it means no supported pattern was detected in that push.
The UK cyber centre's repository guidance also recommends two-factor authentication for access, least privilege for who can change the default branch, and a review of every change that is merged into the version you ship or display. Even on a solo portfolio, opening a pull request and reading the diff before you merge is a cheap way to catch a committed env file.
Step 3. Check the history, not only the latest tree
Deleting a file in a new commit does not remove it from earlier commits. Secret scanning, according to GitHub, covers the entire Git history on all branches. You should do a history check too: look through old commits, discarded branches, and gist links you may have added to your profile.
On a public GitHub repository, open the repository's security views and read any secret-scanning alerts. Official documentation says an alert includes details about the exposed credential, and the first action is to rotate the credential immediately. GitHub also partners with service providers: for some partner secrets, the provider is notified so it can revoke the credential, and those partner findings may not appear as repository alerts. That is another reason to rotate first rather than waiting for a tidy inbox.
If you maintain an organization later, GitHub also documents assessments and additional scanning options, including generic and custom patterns and validity checks that ask whether a detected secret is still active. For a personal public repo, the automatic public scanning plus your own history review is the baseline.
Step 4. If something already leaked, revoke first, then clean up
Follow the official order.
- Revoke or rotate the credential with the provider, and issue a replacement that never goes into Git. UK guidance is explicit: once a secret has been published, you must assume it is compromised. GitHub's documentation makes the same priority: rotate immediately to prevent unauthorized access.
- Check the provider's audit or sign-in logs, if they exist, for use you do not recognize.
- Remove the secret from the working tree and from any hosted demo or CI variable that still uses the old value.
- Only then consider history rewriting, and only if you understand the costs.
GitHub's official guide to removing sensitive data describes a process that starts by rewriting the repository locally with git-filter-repo, then updating the repository on GitHub. It also lists real consequences. Rewriting history changes commit SHAs, which disrupts open pull requests and can invalidate review comments. It can drop commit and tag signatures. And it does not reach every copy: anyone who already cloned the repository still has the old history, and Git's design makes that divergence noticeable. GitHub also notes that if you have already revoked the credential, a full history rewrite is time-intensive and often unnecessary.
Do not force-push and hope. If the leaked material is someone else's personal data or a client's source, tell the person who owns that data and follow their process, even if that means taking the repository private or deleting it.
What to do if a push is blocked, or if a recruiter is waiting
If push protection blocks you, remove the secret from the commits in the push, put a placeholder in the example file, and push again. Do not disable the protection just to land a demo before an interview.
If a recruiter needs to run the project, give them a clean README, a sample env file, and a short screen recording or a deployed demo that uses throwaway keys you can rotate. A broken clone is better than a live key in a public commit.
If you discover a leak after the repo is already on your profile, rotate the key the same day, then leave a short note in the README only if you must explain a rotated integration. You do not need to advertise the mistake; you do need to finish the revocation.
Takeaways
- Treat a public portfolio like a publication: no live secrets, no client data, and no source you do not have the right to share.
- Keep secrets out of the repository, enable push protection and two-factor authentication, and review diffs before they reach the default branch.
- Check Git history and GitHub's secret-scanning results, not only the latest files.
- If a secret is published, revoke it immediately and assume it is compromised; history cleanup is a later, optional step with lasting side effects.
- A clear README and a demo that uses the visitor's own keys is enough to show your work without handing over access to yours.