Commit Carthage dependencies:Source repo strategies

In this lesson

In this lesson, I will teach you some strategies for what to commit and what not to commit to your source code repository when using Carthage


Tap on time to skip ahead


In this lesson, we’re going to talk about committing your code to your source code repository. Here I have MyNewApp. I’ve declared a Cartfile, the Cartfile.private and I’ve run Carthage update to generate the Cartfile.resolved file. What that resulted in is the creation of this Carthage folder and two subfolders: the Build folder, which contains all built artifacts, which are the frameworks and the debug symbols etc, And we have a Checkouts folder, which contains all of the source code of all of the dependency graph declared here and here.


I haven’t even declared my own MyNewApp as a git repo. Let me go ahead and do that in the terminal. I now have a git repo for MyNewApp and we’re going to get ready to commit some code to the repo.


I like to use SourceTree to manage my git repos. Let’s add the existing local repository that I just created from the command line. I’m going to pick MyNewApp. You’ll notice initially that there are lots of files to commit to my repo, even though I haven’t written a single line of code yet in this application. If we open this up, you’ll notice there’s all kinds of files here including the files that are in my Carthage subfolder. We’re going to go through the process of determining what to commit and what not to commit.


In general, it’s a good rule of thumb to ignore anything in your Carthage folders. I’m going to right-click on one of the files and click ignore. You can do this from the command line if you wish. I’m going to say ignore everything beneath Carthage. I’m going to add that to a local .gitignore file for this repo only.


When I do that, you’ll notice that it eliminates the vast majority of files. This is exactly what you typically commit to your source code repository. You’ll want your .gitignore which eliminates anything underneath Carthage. And then you’ll want to commit your Cartfile, your Cartfile.private and your Cartfile.resolved. I’ll do that now. Add initial Carthage dependencies, is a good commit message. There I’ve got my first commit to my Git repo and I’ve shown you what to eliminate.


There is a second school of thought in determining what to commit and what not to commit to your source code repo. Looking at MyNewApp in Finder and expanding the Carthage folder, I have seen some projects include everything in the Checkouts folder. That’s a viable alternative as well. If you do that, the only thing that you need to omit or ignore is everything in the Build folder. You typically don’t want to ever commit that to your source code repo.


Whichever you choose, either ignoring everything beneath Carthage or just everything in the Carthage Build folder. Either way works depending upon your preference.