<?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: Sarath</title>
    <description>The latest articles on DEV Community by Sarath (@sarath191181208).</description>
    <link>https://dev.to/sarath191181208</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%2F1422463%2F8431cf19-fa5d-4037-a395-275c1cf33fa4.png</url>
      <title>DEV Community: Sarath</title>
      <link>https://dev.to/sarath191181208</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sarath191181208"/>
    <language>en</language>
    <item>
      <title>Effective Bash for effortless insights</title>
      <dc:creator>Sarath</dc:creator>
      <pubDate>Sat, 29 Mar 2025 08:22:42 +0000</pubDate>
      <link>https://dev.to/sarath191181208/effective-bash-for-effortless-insights-55pj</link>
      <guid>https://dev.to/sarath191181208/effective-bash-for-effortless-insights-55pj</guid>
      <description>&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; In my company, I was given the following problem. &lt;br&gt;
Get the users who are inactive i.e whose &lt;code&gt;user_activity&lt;/code&gt; data isn't present and they have paid. This is a simple problem, but the way I solved using some clever tricks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Context&lt;/strong&gt;: The user activity data first gets into an s3 bucket, later it gets processed and puts into a mongo collection &lt;code&gt;user_activity&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Stages of solving the problem: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get all the unique users from s3 using athena. &lt;/li&gt;
&lt;li&gt;Get all the users from the mongo collection. &lt;/li&gt;
&lt;li&gt;Get the difference between them. &lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Getting the data from s3
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;create&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="n"&gt;user_data&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nv"&gt;"s3:user_data"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="k"&gt;distinct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;user_data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This I downloaded as csv and saved it in the following path: &lt;code&gt;/tmp/user_ids_in_s3.csv&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting the data from mongo
&lt;/h2&gt;

&lt;p&gt;This was the tricky part because of the way the data is stored and the exports of mongo. &lt;br&gt;
We have the following tables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;user_activity&lt;/code&gt; stores all the user activity.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;user_details&lt;/code&gt; stores the details of the users if he paid or not.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pipelines&lt;/strong&gt; to the rescue. I used mongodb pipelines to get the data of paid users user activity.&lt;br&gt;
The pipelines are something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;$lookup&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user_details&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;localField&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user_id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;foreignField&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;as&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;result&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;$match&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;result.status&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;paid&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;$project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;_id&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;exported this data as json into &lt;code&gt;/tmp/db.user_activity.json&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Where's bash ?
&lt;/h2&gt;

&lt;p&gt;Good question! The way I got the data was in the following format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"$oid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"667..."&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"$oid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"867..."&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, this we are probably going to compare with csv.&lt;br&gt;
Therefore it'll be better if the file was a little nice with just user id's. &lt;/p&gt;
&lt;h2&gt;
  
  
  Bash's rescue
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Getting the user ids from the data in processable format
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; /tmp/db.user_activity.json | 
jq &lt;span class="s1"&gt;'.[]._id."$oid"'&lt;/span&gt; | 
&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/"//g'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; paid_users.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Explination: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cat /tmp/db.user_activity.json&lt;/code&gt; outs the file to stdin.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;jq '.[]._id."$oid"'&lt;/code&gt; print's the oid field from the json.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sed 's/"//g'&lt;/code&gt; cleaning the quotation marks in the data.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt; paid_users.txt&lt;/code&gt; output the whole thing into a file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you don't understand any part feel free to read the docs of each command: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.man7.org/linux/man-pages/man1/cat.1.html" rel="noopener noreferrer"&gt;&amp;gt; man cat&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://devdocs.io/jq/" rel="noopener noreferrer"&gt;&amp;gt; man jq&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.gnu.org/software/sed/manual/sed.html" rel="noopener noreferrer"&gt;&amp;gt; man sed&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/input-output-redirection-in-linux/" rel="noopener noreferrer"&gt;output redirection&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I highly encorage you to work out this command using the following data. &lt;br&gt;
Use this script to generate data: &lt;/p&gt;

&lt;p&gt;✨ This script is generated by AI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_object_id&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;timestamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; 
    &lt;span class="n"&gt;random_bytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getrandbits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;big&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;08&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="si"&gt;}{&lt;/span&gt;&lt;span class="n"&gt;random_bytes&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;[:&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;$oid&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;generate_object_id&lt;/span&gt;&lt;span class="p"&gt;()}}&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generate_data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Comparing "paid users" with "active users"
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;comm&lt;/span&gt; &lt;span class="nt"&gt;-23&lt;/span&gt; &amp;lt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sort&lt;/span&gt; /tmp/user_ids_in_s3.csv&lt;span class="o"&gt;)&lt;/span&gt; &amp;lt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sort&lt;/span&gt; /tmp/paid_users.txt&lt;span class="o"&gt;)&lt;/span&gt; | 
&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s1"&gt;'s/[[:space:]]+//g'&lt;/span&gt; | 
&lt;span class="nb"&gt;sort&lt;/span&gt; | &lt;span class="nb"&gt;uniq&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explination:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;comm -23 &amp;lt;(sort /tmp/user_ids_in_s3.csv) &amp;lt;(sort /tmp/paid_users.txt)&lt;/code&gt;  find the files which are present in one but not both.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sed -E 's/[[:space:]]+//g'&lt;/code&gt; formatting the data as it has spaces at start and end &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sort | uniq&lt;/code&gt; sorting the data and only taking the uniq id's.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you don't understand any part feel free to read the docs of each command: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.man7.org/linux/man-pages/man1/comm.1.html" rel="noopener noreferrer"&gt;&amp;gt; man comm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.man7.org/linux/man-pages/man1/sort.1.html" rel="noopener noreferrer"&gt;&amp;gt; man sort&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.gnu.org/software/sed/manual/sed.html" rel="noopener noreferrer"&gt;&amp;gt; man sed&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.man7.org/linux/man-pages/man1/uniq.1.html" rel="noopener noreferrer"&gt;&amp;gt; man uniq&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/input-output-redirection-in-linux/" rel="noopener noreferrer"&gt;output redirection&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Worthy mention for getting the user ids from the mongo data
&lt;/h4&gt;

&lt;p&gt;My collegue had to do something similar. What he did completely blew my mind. &lt;br&gt;
I never tought of this way so I'm sharing his approach as well.&lt;/p&gt;

&lt;p&gt;He opened the file in vscode and used a regex &lt;code&gt;"$oid": "(.*)"&lt;/code&gt; selected everything using &lt;code&gt;ctrl+f2&lt;/code&gt; and copied them to clipboard.&lt;br&gt;
Pasted this in a new file used &lt;code&gt;alt+shift+end&lt;/code&gt; which goes from the cursors location to the end of the file, &lt;br&gt;
deleted quotations along with the pesky $oid. &lt;/p&gt;

&lt;p&gt;It blew my mind I had never tought of it, altough inefficient and prone to errors. Hat's off. &lt;/p&gt;

</description>
      <category>bash</category>
      <category>programming</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to Hide Local Git Changes Without Ignoring Files</title>
      <dc:creator>Sarath</dc:creator>
      <pubDate>Sun, 16 Mar 2025 08:55:00 +0000</pubDate>
      <link>https://dev.to/sarath191181208/what-git-hide-1da3</link>
      <guid>https://dev.to/sarath191181208/what-git-hide-1da3</guid>
      <description>&lt;h2&gt;
  
  
  TLDR;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.hide &lt;span class="s1"&gt;'update-index --assume-unchanged'&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.unhide &lt;span class="s1"&gt;'update-index --no-assume-unchanged'&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.hidden &lt;span class="s1"&gt;'! git ls-files -v | grep '&lt;/span&gt;^h&lt;span class="s1"&gt;' | cut -c3-
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;p&gt;Has this ever been you problem. You frantically type some code and you have changes in 10 of files and you only need to commit just one of them and all the other files are configuration files or something else that's unique to your machine and this doesn't need to go to the source control.  &lt;/p&gt;

&lt;p&gt;Well, recently I was going through the same problem. I was using a windows machine and my co-workers with a mac. All of them use mac therefore the npm-scripts, linting configuration, dockerfiles  etc... are only mac specific. Therefore, I have to change them to work for my machine. This doesn't need to be pushed to source control. And they are inheritly against choosing an agnostic solution. Therefore, I have almost &lt;strong&gt;10-12&lt;/strong&gt; config files which are specific to my machine. But this messes up with my git status. I wondered is there a way out of this mess. Then Searching through the Internet I found &lt;code&gt;update-index&lt;/code&gt; which is a command in git, it helped me with my problem therefore, I am sharing this with you guys. &lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;There is a concept of &lt;code&gt;index&lt;/code&gt; in git. Basically you can think of index as a snapshot of the repository which git tracks. Basically any command like status, add ..etc will use this index to perform operations with git. So, we just need to update this index. And git generously provides us with this command called &lt;code&gt;update-index&lt;/code&gt;. Which we can use to udpate the index of the git. This inturn will make the changes doesn't appear in git status or anything similar. Which is exactly what we need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git update-index &lt;span class="nt"&gt;--assume-unchanged&lt;/span&gt; file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok, this is all great but what if, I want the changes in the file to be commited how to do that ? As we know that we have updated the index to reflect that the file has no changes we can make sure to say that the file has changes. That can be done in the following way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git update-index &lt;span class="nt"&gt;--no-assume-unchanged&lt;/span&gt; file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will ensure that this file is tracked by git. &lt;/p&gt;

&lt;p&gt;But what if you want to see the hidden files ?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git ls-files &lt;span class="nt"&gt;-v&lt;/span&gt; | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="s1"&gt;'^h'&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-c3-&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add the commands as aliases
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.hide &lt;span class="s1"&gt;'update-index --assume-unchanged'&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.unhide &lt;span class="s1"&gt;'update-index --no-assume-unchanged'&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.hidden &lt;span class="s1"&gt;'! git ls-files -v | grep '&lt;/span&gt;^h&lt;span class="s1"&gt;' | cut -c3-
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;

&lt;p&gt;Rather than typing the long command &lt;code&gt;git update-index --assume-unchanged file.txt&lt;/code&gt; as we have already added this as alias called hide we can do something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git hide file.txt &lt;span class="c"&gt;# same as git update-index --assume-unchanged file.txt&lt;/span&gt;
git unhide file.txt  &lt;span class="c"&gt;# same as  git update-index --no-assume-unchanged file.txt&lt;/span&gt;
git hidden &lt;span class="c"&gt;# same as git ls-files -v | grep '^h' | cut -c3-&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Refrences
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://git-scm.com/docs/git-update-index" rel="noopener noreferrer"&gt;update-index docs&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Inspired from &lt;a href="https://gist.github.com/matriphe/a1ba257bb2cacb8c68f8c0f93252dcff" rel="noopener noreferrer"&gt;github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>git</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
