Roots Discourse

Ignoring Uploads in git

Hey guys,

So I’m building my first project with Sage Roots and I am quite liking it! That being said I think I kinda messed up with regards to git.

I’m not sure if git was already initialised when I installed it (through yarn maybe?) but what I did after installing it was go to the root directory of Wordpress and then ran git init. this seemed to work fine although afterwards I noticed that all of the git files were inside of the theme directory.

So now I’m working and committing stuff from within the theme directory but it always tells me about untracked files in the uploads directory which I do no want.

The thing is…do I not want to commit everything from the root folder down to include plugins and other things in git? I mainly just dont want the uploads folder.

I’m not even sure what happens when I run yarn build:production…does this build everything I need? Should I just change git to look at the theme folder? If so…how do I do this?

Right now if I do a git status it gives me:

Untracked files:
(use “git add …” to include in what will be committed)

../../uploads/cache/184be59f97a0dd64d7f553c3ea53623c790bf01d.php
../../uploads/cache/48359f426dfcabd3bc475f93fbd072d219db88e8.php
../../uploads/cache/80254a7406bc620e090955feda8c99e0905908a5.php

If I amend the gitignore it does not ignore the uploads but I’ve never had it go up directories like this before as my git is normally in the root.

Any help would be greatly appreciated.

What you’ll want to do is add a .gitignore file in the root of your Git repository or WordPress project. GitHub has an example of this file for WordPress. It ignores the wp-content/uploads directory.

You may still find that your Git repository is tracking a lot of files that are meaningless to you which therefore makes your Git history unclear and not useful to you or anyone else who might be involved in your project. If you don’t know what I’m talking about, just wait until you have to update WordPress or a plugin and then you will see. I have an example repo that I used for a talk which aims to demonstrate how hectic it can be over time.

With that being said, Bedrock is the Roots project which aims to improve this experience as well as provide many other benefits.

Bedrock uses Composer to manage WordPress plugins and WordPress itself as dependencies. This means it records the versions of your plugins and WordPress in a file called composer.json in the root of your project, but it doesn’t store the actually files for those dependencies in your Git repository.

I won’t dig into all the details of Bedrock, but I’d encourage you to read more and perhaps consider using it for your WordPress projects in the future if you find it useful. It’ll help you avoid situations like this and encourage you to use best practices.

1 Like