The problem is not particular to GitHub. It's not even particular to the issue of compromised credentials. Recently, we've had the xz backdoor, where a malicious entity slowly wormed themselves into a position of privilege in a project and inserted malicious code. We've had typosquatting and the use of names that sound very much like real, non-malicious modules used to publish malicious python code via standard repositories. We've had any number of thumping vulnerabilities introduced in major pieces of code by completely-authorised developers, without any malfeasance required at all.

The problem isn't limited to free software, either; the SolarWinds exploit used compromised credentials to insert malicious code into an entirely-proprietary software package. In the proprietary world also, fully-authorised developers are capable of doing it to themselves by accident; the CrowdStrike outage of 2024 involved no compromise, but still resulted in "the largest outage in the history of information technology".

So the problem is very real, but it's not specific to free software, it's not specific to compromised credentials, and it's definitely not specific to GitHub. It's not a simple problem, and it doesn't have a single, simple solution. It is, instead, an ongoing battle, in which many weapons may be deployed. These include, but are not limited to, constant vigilance, distribution of privilege, the increased use of schemes that allow one person to verify the correctness of another's work (checksums, digital signatures, reproducible builds), the slow decline of simple username/password authentication in favour of 2FA schemes, the massive increase in SSL deployment spearheaded by Let's Encrypt, and increased awareness of the importance of industrial support for fundamental free-software projects. All of these, and more, have their place in helping us all stay safe.

Edit: I also want to make the point that although the free-software development model may appear more vulnerable to malice (and I'm not sure I accept that that's anything more than an appearance, see above) I think it also really helps deal with things when they go wrong. The xz backdoor didn't make it onto any production systems, which I attribute to two principal characteristics of free software. Firstly, the distribution of labour between code authors, code packagers, and distributors; unlike with CrowdStrike, there's no one person or body whose approval can flush code from the dev systems to the desktops. The malicious code in xz took time to flow through the pipeline, which (fortunately for us all) enabled someone to catch it. Secondly, the availability of source enables anyone with clue to investigate. Andres Freund noticed anomalies in liblzma, and immediately had at his fingertips all the information he needed to dig down into the issue. He didn't have to ask some company's permission to access source under NDA, or worse, call some security hotline, tell them his concerns, and hope they'd be looked into sometime this century.

Answer from MadHatter on Stack Exchange
🌐
GitHub
github.com › orgs › community › discussions › 103073
My Github account seems to have been hacked · community · Discussion #103073
February 1, 2024 - Select Topic Area General Body Someone logged into my account seven hours ago and created a repository. I checked the security log just now. Has anyone encountered a similar situation? I'm not ...
Discussions

security - What happens if a GitHub account for a popular open-source project is hacked? - Open Source Stack Exchange
This might be a basic question, but I’ve been wondering: what happens if the GitHub account of a well-known open-source project is compromised? Could malicious code be added, or an unauthorized upd... More on opensource.stackexchange.com
🌐 opensource.stackexchange.com
January 25, 2025
Claude-powered AI bot just compromised multiple GitHub repos autonomously
I am an autonomous agent that scans public repositories for misconfigured CI/CD workflows. It's a vulnerability scanner with a fancy algorithm tacked in, please save your posts about AI era for LinkedIn, thanks More on reddit.com
🌐 r/cybersecurity
39
373
March 2, 2026
Compromised GitHub Account - Need Assistance Regaining Access
Select Topic Area General Body Five days ago, my GitHub account was hacked. Despite having two-factor authentication (2FA) enabled, the hackers were able to bypass it and change my email address. A... More on github.com
🌐 github.com
3
2
Being hacked
I have been getting hacked for 3 months now. I can see where coding has changed and is rerouting and denying access and it all started with my Microsoft account and someone starting a GitHub accoun... More on github.com
🌐 github.com
2
1
🌐
GitHub
github.com › topics › hacking
hacking · GitHub Topics · GitHub
This repository is maintained by Omar Santos (@santosomar) and includes thousands of resources related to ethical hacking, bug bounties, digital forensics and incident response (DFIR), AI security, vulnerability research, exploit development, reverse engineering, and more.
🌐
Ars Technica
arstechnica.com › security › 2026 › 03 › supply-chain-attack-using-invisible-code-hits-github-and-other-repositories
Supply-chain attack using invisible code hits GitHub and other repositories - Ars Technica
3 weeks ago - The researchers, from firm Aikido Security, said Friday that they found 151 malicious packages that were uploaded to GitHub from March 3 to March 9. Such supply-chain attacks have been common for nearly a decade.
🌐
GitHub
github.com › topics › hacked
hacked · GitHub Topics · GitHub
This repository contains a list of all web sites I come across that are either hacked with or purposefully hosting malware, ransomware, viruses or trojans.
Top answer
1 of 2
47

The problem is not particular to GitHub. It's not even particular to the issue of compromised credentials. Recently, we've had the xz backdoor, where a malicious entity slowly wormed themselves into a position of privilege in a project and inserted malicious code. We've had typosquatting and the use of names that sound very much like real, non-malicious modules used to publish malicious python code via standard repositories. We've had any number of thumping vulnerabilities introduced in major pieces of code by completely-authorised developers, without any malfeasance required at all.

The problem isn't limited to free software, either; the SolarWinds exploit used compromised credentials to insert malicious code into an entirely-proprietary software package. In the proprietary world also, fully-authorised developers are capable of doing it to themselves by accident; the CrowdStrike outage of 2024 involved no compromise, but still resulted in "the largest outage in the history of information technology".

So the problem is very real, but it's not specific to free software, it's not specific to compromised credentials, and it's definitely not specific to GitHub. It's not a simple problem, and it doesn't have a single, simple solution. It is, instead, an ongoing battle, in which many weapons may be deployed. These include, but are not limited to, constant vigilance, distribution of privilege, the increased use of schemes that allow one person to verify the correctness of another's work (checksums, digital signatures, reproducible builds), the slow decline of simple username/password authentication in favour of 2FA schemes, the massive increase in SSL deployment spearheaded by Let's Encrypt, and increased awareness of the importance of industrial support for fundamental free-software projects. All of these, and more, have their place in helping us all stay safe.

Edit: I also want to make the point that although the free-software development model may appear more vulnerable to malice (and I'm not sure I accept that that's anything more than an appearance, see above) I think it also really helps deal with things when they go wrong. The xz backdoor didn't make it onto any production systems, which I attribute to two principal characteristics of free software. Firstly, the distribution of labour between code authors, code packagers, and distributors; unlike with CrowdStrike, there's no one person or body whose approval can flush code from the dev systems to the desktops. The malicious code in xz took time to flow through the pipeline, which (fortunately for us all) enabled someone to catch it. Secondly, the availability of source enables anyone with clue to investigate. Andres Freund noticed anomalies in liblzma, and immediately had at his fingertips all the information he needed to dig down into the issue. He didn't have to ask some company's permission to access source under NDA, or worse, call some security hotline, tell them his concerns, and hope they'd be looked into sometime this century.

2 of 2
4

While the MadHatter has given a comprehensive answer, there is a specific feature of git that allows a measure of security even if someone has received unauthorized write access to the repository: commit signing.

This way, all commits in the git repository show cryptographic proof who authored them (as setting the author and committer to someone else is trivial otherwise).
(as mentioned below, keep in mind that this is only another layer of security, as GPG keys can also be stolen and the passphrase e.g. guessed or keylogged)

Gitlab even has a handy UI feature, which notifies you if the commit was signed, e.g.

🌐
Twingate
twingate.com › blog › tips › GitHub-data-breach
GitHub Data Breach: What & How It Happened? | Twingate
June 28, 2024 - In March 2024, GitHub experienced a security breach involving unauthorized access to code repositories. This incident potentially compromised sensitive information within the repositories and highlighted the ongoing threats facing online platforms.
Find elsewhere
🌐
eSecurity Planet
esecurityplanet.com › home › cybersecurity
GitHub Breach Exposed 700+ Companies in Months-Long Attack | eSecurity Planet
September 9, 2025 - The lesson lands hard, the most ... malware, defined this breach. The hackers downloaded code from multiple GitHub repositories, added guest user accounts, and set up rogue workflows....
🌐
GitHub
github.com › orgs › community › discussions › 127332
Compromised GitHub Account - Need Assistance Regaining Access · community · Discussion #127332
Select Topic Area General Body Five days ago, my GitHub account was hacked. Despite having two-factor authentication (2FA) enabled, the hackers were able to bypass it and change my email address. A...
🌐
InfoWorld
infoworld.com › home › software development › version control systems
Thousands of open source projects at risk from hack of GitHub Actions tool | InfoWorld
March 18, 2025 - Researchers say compromised tool in the GitHub CI/CD environment stole credentials; infosec leaders need to act immediately.
🌐
GitHub
github.com › orgs › community › discussions › 175228
My old github got hacked · community · Discussion #175228
My email was hacked and from there my github, the hacker moved randomly into my accounts hacking them one after the other before i realized it, my github account being one of them. The user set up 2FA after hacking.
🌐
Reddit
reddit.com › r/cybersecurity › red hat confirms security incident after hackers claim github breach
r/cybersecurity on Reddit: Red Hat confirms security incident after hackers claim GitHub breach
October 2, 2025 - This appears to have nothing to do with GitHub itself - RedHat suffered a breach which allowed the hackers to obtain information that granted them access to RedHat's GitHub and their CTRs.
🌐
Hacker News
news.ycombinator.com › item
Hi folks, I'm the CEO of GitHub. GitHub hasn't been hacked. We accidentally ship... | Hacker News
November 9, 2020 - GitHub hasn't been hacked. We accidentally shipped an un-stripped/obfuscated tarball of our GitHub Enterprise Server source code to some customers a couple of months ago. It shares code with github.com. As others have pointed out, much of GitHub is written in Ruby · Git makes it trivial to ...
🌐
GitHub
github.com › Hack-with-Github
Hack with GitHub · GitHub
A collection of various hacking and exploitation tools for hackers and pentesters.
🌐
Git
git.github.io › Hacking-Git
Hacking Git
The goal of this document is not to be a tutorial, but rather to point to interesting material that has already been written · The goal is also not to list all the articles, tools or resources about Git or its internals. There are a lot of good resources, including free books, and the archive ...
Top answer
1 of 1
4

From the OP:

Ok looks like the source has been found.

https://en.internetwache.org/dont-publicly-expose-git-or-how-we-downloaded-your-websites-sourcecode-an-analysis-of-alexas-1m-28-07-2015/

Silly me! :)

PREVENTION -

<DirectoryMatch "^/.*/\.git/">
  Require all denied
</DirectoryMatch> 

in your apache config.

to restore your repo,

git push origin HEAD:master --force

To make it self-contained, though, this happens when you serve an entire Git repo for your website. So, for example, if your deploy process looks like

  1. Push your changes
  2. SSH into the webserver
  3. Pull your changes

Then you should take note.

Git has a .git folder which contains all the meta-information about your repo, including your remote URLs. If you embed your credentials into the remote URL (if it looks like https://user@pass:github.com/user/repo.git, you've done this) then those credentials can be used to access your repository and do anything to it that you could do.

There are a few mitigations, depending on your situation:

  1. As stated above, you can just configure your webserver to not serve the .git folder. This is the quickest, easiest solution, but also not a great one, because you're still exposing the contents of the repo to anyone who knows the paths. If you have any proprietary elements in there at all, use another mitigation.
  2. Put your website's code in some subdirectory of the repository. You still get the ease of deployment, but now anything you want tracked but not published, you just... don't put in the public directory. This is a higher migration cost, but a cleaner approach, and easier to get right in the long run.
  3. Pull with SSH, not with HTTPS. The keyfile, unless you're doing something horribly wrong, won't be published, so no one else can access the repo even if they do have access to the .git folder. Be aware that, with just this solution, they can still access the .git folder, but for some projects (e.g. most open-source ones) this is irrelevant, since everything in there is already public. As a nice side bonus, your server's connecting to GitHub will be more secure.
🌐
TechRadar
techradar.com › pro
GitHub is being hijacked by hackers, and it isn't going to be fixed any time soon | TechRadar
January 12, 2024 - Security Critical AWS supply chain vulnerability could have let hackers take over key GitHub repositories