<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title></title>
    <description>I'm a full stack developer with a strong focus on backend. I like to travel and explore wonderful places. I'm also into photography but I'm still a newbie. I created this site for me to share the things I've learned as a developer.</description>
    <link>https://dev.maryshirl.com/</link>
    <atom:link href="https://dev.maryshirl.com/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Thu, 19 Jul 2018 07:06:16 +0000</pubDate>
    <lastBuildDate>Thu, 19 Jul 2018 07:06:16 +0000</lastBuildDate>
    <generator>Jekyll v3.2.1</generator>
    
      <item>
        <title>Untrack files already pushed to git repository</title>
        <description>&lt;p&gt;This week, I pushed a file to a git repository which later on I realized would be better if the file is not tracked anymore. The file was the &lt;code&gt;coverage/index.html&lt;/code&gt; generated by simplecov gem for my team’s Rails project. Everytime the unit tests are run in our local machine, this file gets updated. There’s no harm in pushing this kind of file but when doing pull requests, I just feel like this adds to the noise.&lt;/p&gt;

&lt;p&gt;Adding a tracked file to &lt;code&gt;.gitignore &lt;/code&gt; will not automatically remove it from being tracked. 
Here’s what I did to untrack it.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h4 id=&quot;step-1-commit--stash-all-your-changes&quot;&gt;Step 1: Commit / stash all your changes&lt;/h4&gt;
&lt;p&gt;This step is not necessary but for precaution, make sure to commit / stash all your changes to avoid them from getting lost.&lt;/p&gt;

&lt;h4 id=&quot;step-2-add-the-file-to-codegitignorecode&quot;&gt;Step 2: Add the file to &lt;code&gt;.gitignore&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;Append the relative path of the file you want to untrack to the &lt;code&gt;.gitignore&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;At this point the file is still being tracked. You can check by doing &lt;code&gt;git status&lt;/code&gt;. Notice that only the &lt;code&gt;.gitignore&lt;/code&gt; file has changes.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://uniim1.shutterfly.com/ng/services/mediarender/THISLIFE/022054767652/media/53983320205/medium/1531839760844/enhance&quot; alt=&quot;Alt Text&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;step-3-remove-the-file-from-index&quot;&gt;Step 3: Remove the file from index&lt;/h4&gt;
&lt;p&gt;Remove the file from the index&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ git rm --cached &amp;lt;file_path&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;When you check the git status, you’ll have something that looks like this
&lt;img src=&quot;https://uniim1.shutterfly.com/ng/services/mediarender/THISLIFE/022054767652/media/53983335711/medium/1531840173502/enhance&quot; alt=&quot;Alt Text&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The deleted file is the file that we want to untrack. It was removed from the cache but is still in our local machine.&lt;/p&gt;

&lt;h4 id=&quot;step-4-add-and--commit-the-changes&quot;&gt;Step 4: Add and  commit the changes.&lt;/h4&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ git add .
$ git commit -m '&amp;lt;commit_message&amp;gt;'
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;You have now removed your file from being tracked by git.&lt;/p&gt;

&lt;div class=&quot;PageNavigation&quot;&gt;
  
  
&lt;/div&gt;

</description>
        <pubDate>Fri, 07 Jul 2017 18:00:00 +0000</pubDate>
        <link>https://dev.maryshirl.com/articles/untrack-files-pushed-to-repository.html</link>
        <guid isPermaLink="true">https://dev.maryshirl.com/articles/untrack-files-pushed-to-repository.html</guid>
        
        <category>git</category>
        
        
        <category>articles</category>
        
      </item>
    
  </channel>
</rss>
