<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Brice Friha</title>
    <description>The latest articles on DEV Community by Brice Friha (@bricefriha).</description>
    <link>https://dev.to/bricefriha</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F335524%2Fca5c8b03-a33b-4f24-9e72-7f74e2c47a16.jpg</url>
      <title>DEV Community: Brice Friha</title>
      <link>https://dev.to/bricefriha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bricefriha"/>
    <language>en</language>
    <item>
      <title>How to remove your secrets from your Git repository?</title>
      <dc:creator>Brice Friha</dc:creator>
      <pubDate>Wed, 11 Sep 2024 10:04:59 +0000</pubDate>
      <link>https://dev.to/bricefriha/how-to-remove-your-secrets-from-your-git-repository-3lcc</link>
      <guid>https://dev.to/bricefriha/how-to-remove-your-secrets-from-your-git-repository-3lcc</guid>
      <description>&lt;p&gt;&lt;em&gt;[you can skip the intro and copy the command line directly, I'm just pretending being a writer here]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It happened once, at some point in my career, that someone in my team may or may not have pushed a settings file containing secrets to our remote repo (look at that dude, being vague, trying not to get his colleagues in trouble). When I discovered that, I was in panic mode. but then I've found a perfect solution that would erase this file from ever existing on the your repo.&lt;/p&gt;

&lt;p&gt;Since I had to reuse this a couple of other times later (sometimes when I f-ed up myself) I thought it would be a good idea to document it... then 1565168 years has passed and here I am today...&lt;/p&gt;

&lt;h2&gt;
  
  
  How do one erase their cringiness of the past from their repository
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;This instruction aims at deleting a file containing a secret forever from a repo, if you hardcoded a secret to a file that you still need to your repo, I can't do anything for you... but also, Chat GPT might have told you to do it so I think you have bigger fish to fry&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's checkout on to the branch that has this file (it's better if it's your master branch but you do whatever I'm not your dad):&lt;br&gt;
&lt;code&gt;git checkout main&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you are to afraid of making a mess, that's fair, you can even create a branch from this branch:&lt;br&gt;
&lt;code&gt;git checkout -B main/imayfckup&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After this, let's remove that config file:&lt;br&gt;
&lt;code&gt;git filter-branch --force --index-filter "git rm --cached --ignore-unmatch /path/to/my/onlyfans/credentials.json" --prune-empty --tag-name-filter cat -- --all&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;replace the path with your own when you copy/paste, please don't be this person (aka me when I 'read' docs)&lt;br&gt;
It's gonna take a long time, surely enough time to go in the corner and think about what you've done.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, come back to your desk, and let's add the file to your &lt;code&gt;.gitignore&lt;/code&gt; file:&lt;br&gt;
&lt;code&gt;echo "/path/to/my/onlyfans/credentials.json" &amp;gt;&amp;gt; .gitignore&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;we stage:&lt;br&gt;
&lt;code&gt;git add .gitignore&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We commit:&lt;br&gt;
&lt;code&gt;git commit -M "my mommy will never find out"&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;To end with, let' do something ugly and push force the crap out of the changes (forgive me father for all my sins)&lt;br&gt;
&lt;code&gt;git push origin --force --all&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and that's it.&lt;br&gt;
NOW:&lt;br&gt;
it's very important you rebase all the branches that depend on this branch. Not &lt;code&gt;merge&lt;/code&gt; I said &lt;code&gt;rebase&lt;/code&gt;, otherwise this file will comeback to hunt you, like the Grammarly subscription I forgot to cancel months ago&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;... Just kidding! &lt;br&gt;
there is no point writing conclusion it's a tutorial not an essay.&lt;/p&gt;

&lt;p&gt;That's all, have a nice day!&lt;/p&gt;

</description>
      <category>git</category>
      <category>programming</category>
      <category>security</category>
    </item>
  </channel>
</rss>
