Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As already been said, to exclude from status just use:</p> <pre><code>git status -uno # must be "-uno" , not "-u no" </code></pre> <p>If you instead want to permanently ignore currently untracked files you can, from the root of your project, launch:</p> <pre><code>git status --porcelain | grep '^??' | cut -c4- &gt;&gt; .gitignore </code></pre> <p>Every subsequent call to <code>git status</code> will explicitly ignore those files.</p> <p><strong>UPDATE</strong>: the above command has a minor drawback: if you don't have a <code>.gitignore</code> file yet your gitignore will ignore itself! This happens because the file <code>.gitignore</code> gets created before the <code>git status --porcelain</code> is executed. So if you don't have a <code>.gitignore</code> file yet I recommend using:</p> <pre><code>echo "$(git status --porcelain | grep '^??' | cut -c4-)" &gt; .gitignore </code></pre> <p>This creates a subshell which completes <em>before</em> the <code>.gitignore</code> file is created.</p> <p><strong>COMMAND EXPLANATION</strong> as I'm getting a lot of votes (thank you!) I think I'd better explain the command a bit:</p> <ul> <li><code>git status --porcelain</code> is used instead of <code>git status --short</code> because <a href="https://www.kernel.org/pub/software/scm/git/docs/git-status.html" rel="noreferrer">manual</a> states "Give the output in an easy-to-parse format for scripts. This is similar to the short output, but will remain stable across git versions and regardless of user configuration." So we have both the parseability and stability;</li> <li><code>grep '^??'</code> filters only the lines starting with <code>??</code>, which, according to the <a href="https://www.kernel.org/pub/software/scm/git/docs/git-status.html" rel="noreferrer">git status manual</a>, correspond to the untracked files;</li> <li><code>cut -c4-</code> removes the first 3 characters of every line, which gives us just the relative path to the untracked file;</li> <li>the <code>|</code> symbols are <a href="http://en.wikipedia.org/wiki/Redirection_%28computing%29#Piping" rel="noreferrer">pipes</a>, which pass the output of the previous command to the input of the following command;</li> <li>the <code>&gt;&gt;</code> and <code>&gt;</code> symbols are <a href="http://en.wikipedia.org/wiki/Redirection_%28computing%29#Variants" rel="noreferrer">redirect operators</a>, which append the output of the previous command to a file or overwrites/creates a new file, respectively.</li> </ul> <p><strong>ANOTHER VARIANT</strong> for those who prefer <a href="https://unix.stackexchange.com/a/24151/49405">using <code>sed</code></a> instead of <code>grep</code> and <code>cut</code>, here's another way:</p> <pre><code>git status --porcelain | sed -n -e 's/^?? //p' &gt;&gt; .gitignore </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload