<?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: Raghunathan R</title>
    <description>The latest articles on DEV Community by Raghunathan R (@raghunathan_r).</description>
    <link>https://dev.to/raghunathan_r</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%2F536770%2Fa52ee774-c59c-46d4-a805-29263298ba01.png</url>
      <title>DEV Community: Raghunathan R</title>
      <link>https://dev.to/raghunathan_r</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/raghunathan_r"/>
    <language>en</language>
    <item>
      <title>How to remove a sensitive file from GitHub</title>
      <dc:creator>Raghunathan R</dc:creator>
      <pubDate>Fri, 29 Jan 2021 13:48:23 +0000</pubDate>
      <link>https://dev.to/raghunathan_r/how-to-remove-a-sensitive-file-from-github-1o64</link>
      <guid>https://dev.to/raghunathan_r/how-to-remove-a-sensitive-file-from-github-1o64</guid>
      <description>&lt;p&gt;Yes! this has happened to most of the people, especially when we are just starting. We accidentally commit sensitive data to GitHub. We forget to gitignore our config file containing database passwords or API keys or jwt secrets. And we immediately start to panic.&lt;/p&gt;

&lt;p&gt;This happened to me a couple of days ago. I forgot to ignore my default JSON file that contained my database connection password and jwt secret. I had just gotten a feature to finally work and in the excitement, I immediately committed and pushed to GitHub. I only realized my error when I got a notification from GitGuardian that my latest commit contained secret keys.&lt;/p&gt;

&lt;p&gt;If you find yourself in the same position, the first thing you do is change the visibility of the repo. So, if it's a public repo, make it private. This way, you're sure no one else sees the file while you're working on deleting it.&lt;/p&gt;

&lt;p&gt;Next thing, if you aren't already in the project folder, cd into it on git bash or whatever terminal you are using. Let's assume my project folder is My-Project and I have a file named secretFile.json I want to delete.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd My-Project&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then run the following command. You have to include the path to the file and not just the file name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch config/secretFile.json" \
  --prune-empty --tag-name-filter cat -- --all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;replacing config/secretFile.json with the path to the file you want to be removed. In my case, secretFile.json is inside of a folder named config.&lt;/p&gt;

&lt;p&gt;Note: The command above deletes the file from your local repository too, so ensure you have copied the content to a notepad or whatever you use before running the command.&lt;/p&gt;

&lt;p&gt;Then create and add your file to .gitignore so you don't accidentally push it to GitHub again. You can do that with&lt;/p&gt;

&lt;p&gt;&lt;code&gt;echo "name-of-your-file" &amp;gt;&amp;gt; .gitignore&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git add .gitignore&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git commit -m 'add file to .gitignore'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once you are satisfied with your changes, you can then push them to GitHub&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git push origin --force --all&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And that's it! Your repo history is clean without any trace of your sensitive file.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>github</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
