🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🪟 Windows TippsHeader and Footer not showing in Excel(14.09.2026 um 22:43 Uhr)
🕵️ SicherheitslückenBurn Out, Or Fade Away(14.09.2026 um 14:25 Uhr)
🪟 Windows TippsKB5129194 Windows 11 26H1 Out of Band Update - Deskmodder.de(14.09.2026 um 19:25 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🪟 Windows TippsHeader and Footer not showing in Excel(14.09.2026 um 22:43 Uhr)
🕵️ SicherheitslückenBurn Out, Or Fade Away(14.09.2026 um 14:25 Uhr)
🪟 Windows TippsKB5129194 Windows 11 26H1 Out of Band Update - Deskmodder.de(14.09.2026 um 19:25 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 2 Min Lesezeit
0

How to Remove Git Commit History While Keeping Your Main Branch Intact

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

If you’ve ever wanted to clean up your Git repository by removing its commit history while keeping the latest version of your code intact, have a read. This post explains how to achieve this using Git.









Why Clear Git History?



There are a few reasons you might want to clean up your commit history:




  • You would like your repo to have a clean commit history.

  • Sensitive data was accidentally pushed and needs removal.

  • The repository has too many unnecessary or cluttered commits.




Important Note: The process below is irreversible. Proceed with caution!










Steps to Remove Git History While Keeping the Main Branch Intact






Step 1: Clone the Repository






CODE
git clone https://github.com/username/repository.git
cd repository









Step 2: Create a New Branch Without History






CODE
git checkout --orphan new-main






This creates a fresh branch with no previous commit history.






Step 3: Add All Files






CODE
git add .






Stage all files from the working directory.






Step 4: Commit the Current State






CODE
git commit -m "Initial commit with current state"






Make a new commit reflecting the current project state.






Step 5: Delete the Old Main Branch






CODE
git branch -D main






Remove the old branch locally.






Step 6: Rename the New Branch to Main






CODE
git branch -m main






Rename the new branch to main.






Step 7: Force Push to GitHub






CODE
git push --force origin main






Push the new branch to the remote repository, overwriting the old history.









What About GitHub Activities?



Even after removing commit history, GitHub's Activities tab will still display past events like pushes, pull requests, and issue tracking. This happens because GitHub tracks these separately from your Git commit history.






How to Limit Activity Visibility:





  1. Make the Repository Private:




    • Go to Settings in your GitHub repository.

    • Scroll down to Danger Zone and click Make Private.




  2. Create a New Repository:




    • Delete the old repository if historical activity is problematic.

    • Create a new repository and push the cleaned code.




  3. Transfer Repository Ownership:




    • Transfer the repository to another account, which can reset some public logs.




  4. Consider GitHub Enterprise:




    • Use GitHub Enterprise for advanced control over activity visibility.











Final Thoughts



Removing Git commit history is useful for starting fresh, but keep in mind that GitHub’s Activities tab will still retain a record of past events. If a completely clean public record is essential, creating a new repository is your best option.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
The Gemini desktop app is now available for Windows
1 Quelle
Header and Footer not showing in Excel
1 Quelle
Burn Out, Or Fade Away
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten How to Remove Git Commit History While Keeping Your Main Branch Intact

Thematisch verwandte Begriffe: Remove, Commit, History, While · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...