Azure Tips and Tricks - Remove Azure Secrets committed to GitHub
Remove Azure Secrets committed to GitHub
Remove passwords committed to GitHub on accident
Writing code day after day means secrets, connection strings and more get added to your code accidentally. And if you are like me, they get committed to your GitHub repo and then you have to live in shame. =) In this post, I'll walk you through removing secrets from a GitHub repo that you've already committed the secret to.
Part 1 - Initial setup:
Scenario: You have committed a password with the value of qph@}uC,7cGLBdsX to your GitHub repo. This password should be confidential and not stored in the code.
How do you fix it?
- Ensure you have the repo on your local disk or clone a fresh copy with HTTPS or SSH. I'll use SSH
git clone [email protected]:mbcrump/crumpbot.gitas a sample. - Clone a copy of your repo that has the secret stored using the mirror option, like the following
git clone --mirror [email protected]:mbcrump/crumpbot.git. - You'll now have a BARE repo. CD into it with
cd crumpbot.gitand runls -lto list out the contents on macOS ordiron Windows.
Below is an example of my repo.
Part 2 - Create a file of passwords that you'd like to remove:
- Create a
passwords.txtfile and place and enter the passwords that you'd like to remove from your GitHub repo.
I created mine on macOS with touch passwords.txt or echo some-text > passwords.txt on Windows and added the password that I accidentally committed:
- Save the file.
Part 3 - Install BFG:
Enter BFG (opens new window). According to the author:
BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history: Removing Crazy Big Files Removing Passwords, Credentials & other Private data
- Install BFG with
brew install bfgassuming you have Homebrew installed and using a Mac or download the JAR file if you are on Windows.
Part 4 - Clean up the passwords previously committed:
-
Run
bfg --replace-text passwords.txt crumpbot.giton Mac orjava -jar bfg.jar --replace-text passwords.txt crumpbot.gitif using the JAR file. -
Below is output from that command:
Part 5 - Pushing to GitHub:
- Run
git reflog expire --expire=now --all && git gc --prune=now --aggressiveas indicated by the output. - Run
git pushto push it to your repo.
Part 6 - Wrap-up and verify your repo was updated successfully:
If you go back to your GitHub repo and look at prior commits, then you should see REMOVED like the following:
I hope this helps someone out there and if you want to stay in touch then I can be found on Twitch, Twitter or GitHub.
Create a trial account today and go and check it out!
Published on:
Learn moreRelated posts
Azure SDK Release (October 2025)
Azure SDK releases every month. In this post, you'll find this month's highlights and release notes. The post Azure SDK Release (October 2025)...
Microsoft Copilot (Microsoft 365): [Copilot Extensibility] No-Code Publishing for Azure AI Foundry Agents to Microsoft 365 Copilot Agent Store
Developers can now publish Azure AI Foundry Agents directly to the Microsoft 365 Copilot Agent Store with a simplified, no-code experience. Pr...
Azure Marketplace and AppSource: A Unified AI Apps and Agents Marketplace
The Microsoft AI Apps and Agents Marketplace is set to transform how businesses discover, purchase, and deploy AI-powered solutions. This new ...
Episode 413 – Simplifying Azure Files with a new file share-centric management model
Welcome to Episode 413 of the Microsoft Cloud IT Pro Podcast. Microsoft has introduced a new file share-centric management model for Azure Fil...
Bringing Context to Copilot: Azure Cosmos DB Best Practices, Right in Your VS Code Workspace
Developers love GitHub Copilot for its instant, intelligent code suggestions. But what if those suggestions could also reflect your specific d...
Build an AI Agentic RAG search application with React, SQL Azure and Azure Static Web Apps
Introduction Leveraging OpenAI for semantic searches on structured databases like Azure SQL enhances search accuracy and context-awareness, pr...
Announcing latest Azure Cosmos DB Python SDK: Powering the Future of AI with OpenAI
We’re thrilled to announce the stable release of Azure Cosmos DB Python SDK version 4.14.0! This release brings together months of innov...
How Azure CLI handles your tokens and what you might be ignoring
Running az login feels like magic. A browser pops up, you pick an account, and from then on, everything just works. No more passwords, no more...
Boost your Azure Cosmos DB Efficiency with Azure Advisor Insights
Azure Cosmos DB is Microsoft’s globally distributed, multi-model database service, trusted for mission-critical workloads that demand high ava...
Microsoft Azure Fundamentals #5: Complex Error Handling Patterns for High-Volume Microsoft Dataverse Integrations in Azure
🚀 1. Problem Context When integrating Microsoft Dataverse with Azure services (e.g., Azure Service Bus, Azure Functions, Logic Apps, Azure SQ...