Search code examples
wordpressgitgitignore

Ignore only files on the root of the project on Git


I am developing a wordpress site, in my .gitignore file I put the wordpress core files, among these files there is the xmlrpc.php file, on the other hand I have a plugin which contains a file from the same name "xmlrpc.php" so it was ignored too.

How can I ensure that only the xmlrpc.php file on the site root is ignored ?

Here is what I have in my .gitignore file:
#WordPress core files
wp-admin
wp-includes
xmlrpc.php
index.php
wp-activate.php
wp-blog-header.php
wp-comments-post.php
wp-cron.php
wp-links-opml.php
wp-load.php
wp-login.php
wp-mail.php
wp-settings.php
wp-signup.php
wp-trackback.php


Solution

  • Prepend the filename with a slash / to only match files in the repository root. That is, your .gitignore should look like:

    #WordPress core files
    wp-admin
    wp-includes
    /xmlrpc.php
    index.php
    ...
    

    Add a / before all the filenames that this applies to.