Logo
Logo

Programming by Stealth

A blog and podcast series by Bart Busschots & Allison Sheridan.

PBS Tidbit 9 of Y: Using Git on iOS (Git)

10 Oct 2024

For a long time, I assumed iOS couldn’t provide a good Git experience because of its security-first design. In iOS, your data is protected from unauthorised access because each app lives in its own little playpen (or sandbox to use the correct jargon). That appears to rule out the traditional approach I use on my Macs where I have a Git client for interacting with my repositories, and I make my edits in whichever one of my many editing apps I find most appropriate to the type of file I need to edit.

As I understood it, the only hope for Git on iOS would be to find a single app that was both a Git client and a really good editor for every single type of file I wanted to edit. This hypothetical all-in-one app would have no problem with iOS’s sandboxing because everything would live within that one app’s playpen. But what are the chances of finding such a unicorn app‽

In the early days of iOS what I described above was true, but iOS has moved on, and while Apple still make it possible to treat iOS as if it has no file system at all, Apple do now let you create and manage files and folder in your local device through the built-in Files app.

But, Apple didn’t just make it possible for you to manage files, they also provided APIs for developers to give their apps the power to reach outside of their sandboxes, but only in a very controlled way. The only way any app gets out of its sandbox is by you, the user, explicitly opening the file or folder on behalf of the app, without your interaction, the app is trapped. This lets iOS retain its strong security posture while also letting multiple apps access the same files and folders.

This is where NosillaCastaway Jill of Kent comes into the picture, while we were publishing our long series within a series on Git, Jill shared some feedback that she was playing along on her iPad, and that literally blew my mind! Based on Jill’s recommendation I installed the same iOS Git client she was using, and I’ve been happily Gitting on my iPhone and iPad ever since!

Matching Podcast Episode

You can also Download the MP3

Read an unedited, auto-generated transcript with chapter marks: PBS_2024_10_10

How it Works Conceptually

Regardless of which iOS Git app and which iOS editors you choose to use, conceptually, you’ll be working in the same way:

  1. Create a local folder on your iOS device using the Files app
  2. Use a Git app to convert that folder into a local Git repository and optionally connect it to a remote Git server
  3. Use any editing app that supports iOS’s local file access APIs to edit the files in the local Git repository.

A Walk-Through Using My Apps of Choice

Prerequisites

Initial Setup of a Repo

Step 1 — Create a Local Folder

Open the Files app, and navigate to the ‘on my iPhone/iPad’ top-level section.

Click the three dots icon and then ‘new folder’.

Open iOS Files app and select on my iPhone iPad
Open Files App to Browse
& Choose On my iPhone (or iPad)
Select 3-dot icon in the upper right
Select 3-Dot Menu
Create a new folder in the iOS Files app
Select New Folder
New folder visible in Files App
Your Shiny New Folder Showing 0 Items

Step 2 — Configure the Folder as a Git Repo

Open Working Copy, and at the top level page that lists all your repos, click the button that looks like a plus symbol on top of a fingerprint, select ‘Link external directory’ and then ‘Directory’ from the dropdown to connect to the folder you just created in the Files app.

Select fingerprint plus button
In Working Copy Select Fingerprint + Button
Open Link external repository, then select directory
Tap Link External Repo
Select Directory
Do NOT Select Clone Repo
Select the folder on your device that you created earlier
Select Folder You Created in Files
Select Open and note folder is currently empty
In Emtpy Folder Select Open

You now have an empty local Git repo with no commits. To use your Git server, you need to add a remote to this local repo. 

Step 3 — Add a Remote to the Local Repo

Before you go any further, you’ll need to fetch the URL for your desired repo on your Git server. For fellow GitHub users, note that you’ll need to use the web interface, because I have not found a way of getting the GitHub iOS app to show the SSH URL for a repo!

Open GitHub repo select Code and then copy SSH URL
In GitHub Copy the SSH Url for the Code

In Working Copy, go into the new linked shared folder and click the word ‘Repository’ (not the icon to the right):

Select Repository NOT the branch link or chevron on the right
Back In Working Copy Tap on Repository
NOT Icons on Right

On the repository setting page, click the ‘Configuration’ button:

Open the Configuration interface in the Working Copy repository
Select Configuration

You’ll see one or more Git identities in a list that doesn’t look like a list at the top of the page — select the identity you set up in Working Copy that’s connected to your server. For me, that’s my GitHub account. When you have an identity ticked, back out to the repository settings page again.

Tap on the identity name, NOT Edit
Tap on the Identity You Want to Use
If you have done it right you will see a checkmark next to the identity. Hit the back chevron
If You Did it Right
You Should See a Checkmark
Tap Back Chevron

Now that Working Copy knows which authentication details to use, you’re ready to link your local repo to the appropriate repo on your server.

Click the button to add a remote and paste in the URL you fetched earlier.

Click the Add Remote button
Tap Add Remote
Many things to touch ignore all but URL field and paste SSH URL from GitHub
Paste the SSH URL from GitHub Tap Save

Back on the repository setting page, click the three dots and choose ‘fetch’, which should retrieve the list of remote branches:

Select 3-dot menu
Tap 3-dot Menu
Choose Fetch to see the remote branches in Working Copy and then select Branch
Select Fetch

Note that you can’t yet pull because the branch you have checked out is your local main branch which has no commits yet so it is unborn. Pushing and pulling is only possible when you have local branches linked to remote branches. So, that’s what we need to arrange next.

Note that what the interface now shows you is all the branches that exist both locally and remotely, with the local branches on top (there will be just main), and the remote branches below.

Green success of fetching data and select branch
Select Branch
Selecting a remote branch
Choose Your Desired Branch
Select Checkout on that remote branch
Select Checkout

To start using files from the remote repository you need to check out a remote branch. It doesn’t matter which one you check out, but you need to check at least one out (no reason you can’t check out more later). Once you check out a remote branch you will see a copy of it above the divider as a local branch, and it will be linked to the remote branch you checked. Now that you have a local branch connected to a remote branch you can push and pull changes to and from the remote repository.

Branch checked out showing files pulled
Ready to Get to Work
Check the folder in files on my iPhone
In Files Verify the Repo is there
by Opening the Folder
Opened folder shows the files from the cloned repo - no longer empty
Files Happily On iPhone

Step 4 —Textastic

Open Textastic and choose Add External Folder… Then navigate through the Files app to On My iPhone and select the repo folder.

Textastic highlighting Add External Folder
In Textastic Add External Folder
Navigate to Files and on my iPhone and select the repo folder
Navigate to On My iPhone in Files
& Select Repo Folder
Textastic shown editing one of the Markdown files in the repo
Open Text File
and Go to Town in Textastic

Day-to-Day Use

  1. Check out the desired branch in Working Copy
  2. Open the folder in your text editor of choice and make your edits
  3. Use Working Copy to commit, push, pull etc.

Final Thoughts

Regardless of whether or not you end up choosing the same apps I did, if you’re an iPhone and/or iPad user, I hope I’ve armed you with enough information and inspiration to start experimenting with Git on iOS.

Join the Community

Find us in the PBS channel on the Podfeet Slack.

Podfeet Slack