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)
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.