DEV Community

Victoria Drake
Victoria Drake

Posted on • Originally published at victoria.dev on

A remote sync solution for iOS and Linux: Git and Working Copy

I previously wrote about a (hackish) way to use a single Dropbox folder on a dual-boot Windows and Linux machine. I’ve since gained some sense gone full Linux with Ubuntu 18.04 LTS, but the Dropbox set up seems to have stopped being an option in any case. Fortunately, I’ve since found a much better (far less hackish) way to remote-sync files across different file systems. Reflecting my current set up, I’m talking about iOS (iPad and iPhone) and my Linux machine.

The new sync system is based on Git, very customizable, and conveniently extensible. Beyond text files, you can sync anything that Git can (which is almost everything - if you want to edit your .gitignored files on the go I’m not sure I can help). If you’re already familiar with Git, getting set up will be a walk in the park. If Git is new to you, I think these tools help make the concepts of Git cloning, pulling, and pushing straightforward to understand.

Components

  • Working Copy app ($15.99 one-time pro-unlock and well worth it, iOS only)
  • iA Writer app ($8.99 one-time purchase for iOS, also available on Mac, Windows, and Android)
  • GitHub repositories (private or public, both free)

I was inspired by this article as well as this one.

Get set up

Here are the steps to setting up that I’ll walk you through in this article.

  1. Create your remote repository
  2. Clone repository to iPad with Working Copy
  3. Open and edit files with iA Writer
  4. Push changes back to remote
  5. Pull changes from repository on your computer

This system is straightforward to set up whether you’re a command line whiz or just getting into Git. Let’s do it!

Create your remote repository

GitHub now offers free private repositories for up to three collaborators. Choose “Private” on GitHub’s repository creation page:

Selection options for public and private repository

Create the repository. If you’d like to, you can follow GitHub’s instructions to push some files to it from your computer, or you can add files later from your iPad.

Clone repository to iPad with Working Copy

Download Working Copy from the App Store. It’s one of the more expensive apps I’ve purchased, but I think it’s well worth it. Developer Anders Borum has a steady track record of frequent updates and incorporating the latest features for iOS apps, like drag and drop on iPad. I think he’s fairly priced his product in light of the work he puts into maintaining and enhancing it.

In Working Copy, find the gear icon in the top left corner and touch to open Settings.

Settings menu in Working Copy

Tap on SSH Keys, and you’ll see this screen:

SSH Key for Working Copy on iPad

SSH keys, or Secure Shell keys, are access credentials used in the SSH protocol. Your key is a password that your device will use to securely connect with your remote repository host - GitHub, in our example. Since anyone with your SSH keys can potentially pretend to be you and gain access to your files, it’s important not to share them accidentally, like in a screenshot on a blog post.

Tap on the second line that looks like “WorkingCopy@iPad-xxxxxxxx” to get this screen:

Connect to GitHub or Bitbucket in Working Copy

Working Copy supports easy connection to both BitBucket and GitHub. Tap “Connect With GitHub” or BitBucket to bring up some familiar sign-in screens that will authorize Working Copy to access your account(s).

Once connected, tap the “+” symbol in the top right of the side bar to add a new repository. Choose “Clone repository” to bring up this screen:

Loading repositories from remote

Here, you can either manually input the remote URL, or simply choose from the list of repositories that Working Copy fetches from your connected account. When you make your choice, the app clones the repository to your iPad and it will show up in the sidebar. You’re connected!

Open and edit files with iA Writer

One of the (many) reasons I adore iA Writer is its ability to select your freshly cloned remote repository as a Library Location. To do this in the iA Writer app:

  1. From the main Library list, in the top right of the sidebar, tap “Edit”
  2. Tap “Add Location…”
  3. A helpful popup appears. Tap OK.
  4. From the Working Copy location, tap “Select” in the top right, then choose the repository folder.
  5. Tap “Open”, then “Done”

Your remote repository now appears as a Location in the sidebar. Tap on it to work within this directory.

While inside this location, new files you create (by tapping the pencil-and-paper icon in the top right corner) will be saved to this folder locally. As you work, iA Writer automatically saves your progress. Next, we’ll look at pushing those files and changes back to your remote.

Push changes back to remote

Once you’ve made changes to your files, open Working Copy again. You should see a yellow dot on your changed repository.

Yellow dot indicating changes to repository

Tap on your repository name, then on “Repository Status and Configuration” at the top of the sidebar. Your changed files will be indicated by yellow dots or green “+” symbols. These mean that you’ve modified or added files, respectively.

Working Copy is a sweet iOS Git client, and you can tap on your files to see additional information including a comparison of changes (“diff”) as well as status and Git history. You can even edit files right within the app, with syntax highlighting for its many supported languages. For now, we’ll look at how to push your changed work to your remote repository.

Changes to commit

On the “Repository Status and Configuration” page, you’ll see right at the top that there are changes to be committed. If you’re new to Git, this is like “saving your changes” to your Git history, something typically done with the terminal command git commit. You can think of this as saving the files that we’ll want to send to the GitHub repository. Tap “Commit changes.”

Add a commit message and select files to commit

Enter your commit message, and select the files you want to add. Turn on the “Push” switch to send everything to your remote repository when you commit the files. Then tap “Commit.”

You’ll see a progress bar as your files are uploaded, and then a confirmation message on the status screen.

Commit success message

Congratulations! Your changes are now present in your remote repository on GitHub. You’ve successfully synced your files remotely!

Pull changes from repository on your computer

To bring your updated files full circle to your computer, you pull them from the GitHub repository. I prefer to use the terminal for this as it’s quick and easy, but GitHub also offers a graphical client if terminal commands seem a little alien for now.

If you started with the GitHub repository, you can clone it to a folder on your computer by following these instructions.

Staying in sync

When you update your work on your computer, you’ll use Git to push your changes to the remote repository. To do this, you can use GitHub’s graphical client, or follow these instructions.

On your iOS device, Working Copy makes pulling and pushing as simple as a single tap. On the Repository Status and Configuration page, tap on the remote name under “Remotes”.

List of Remotes in Working Copy

Then tap “Synchronize”. Working Copy will take care of the details of pushing your committed changes and/or pulling any new changes it finds from the remote repository.

Not bad, right?

For a Git-based developer and work-anywhere-aholic like me, this set up couldn’t be more convenient. Working Copy really makes staying in sync with my remote repositories seamless, nevermind the ability to work with any of my GitHub repos on the go.

For editing on the go, here’s a useful tip. Use .gitignore in your sync repository if you don’t need to move large files, like images, around with you. This will stop the ignored files from being pushed to GitHub and pulled to your iOS device - they’ll only remain on your computer’s larger hard drive. The .gitignore file of one of my sync repositories looks like this:

*.png
*.jpeg
*.jpg
*.mp4
*.gif
Enter fullscreen mode Exit fullscreen mode

This means all the media files stay on my computer, and I can pull just the text file content to my iPad from GitHub to work on while I’m out and about.

I most recently used this set up to get some writing done while hanging out in the atrium of Washington DC’s National Portrait Gallery, which is pleasantly photogenic.

The atrium of the National Portrait Gallery

I’d love to hear how this set up works for you and how you use it. In the meantime, happy working!

Top comments (0)