The GitHub logo.

There are many ways you can manage and store your writing projects. Some people prefer cloud storage services (like Dropbox) or online editors (like Google Docs), while others use desktop applications (like Microsoft Word). I use something called GitHub.

GitHub: It’s for More Than Just Code

I use Git and GitHub to store and access all of my writing. Git is an effective tool you can use to track document changes, plus you can upload to GitHub super-fast. It’s also quick and simple to download your work to a second or third device.

If you’ve never heard of GitHub, it’s the world’s most popular destination to store and maintain open-source code. That might sound like a crazy place to host your writing, but it’s not! After all, code is just lines and lines of text, like your article, story, or dissertation.

Around 2013, GitHub started encouraging people to create repositories for all kinds of information, not just code. GitHub never really left its coding roots, but some people still use it to store writing and other non-coding projects. For example, one person used Git and GitHub to write an instructional book, while another wrote a novel. Poke around on Google, and you find all kinds of crazy uses for GitHub.

What Are Git and GitHub?

A GitHub repository's tabbed interface.
The informational section of a GitHub repository.

Git is an open-source program created by Linus Torvalds, of Linux fame. Git tracks changes to documents and makes it easier for multiple people to work on the same document remotely. In tech-speak, it’s called a distributed version control system (or distributed VCS). Git doesn’t arbitrarily save versions of your documents at set intervals. Instead, it stores changes to your documents only when you tell it to.

Your documents form a repository (or repo), which is just a fancy term for your project folder. Your Documents folder in Windows, for example, would be a repository if you used Git to manage it (but don’t do that).

When you store changes to your documents in Git, it’s called a “commit.” A commit is just a record of the most recent changes you made to a document. Each commit is assigned a long string of numbers and letters as its ID.

If you call up a past commit by its ID, you don’t see the entire project as you do in Word’s document history. You only see the most recent changes when that commit was made. However, this doesn’t mean the entire project wasn’t recorded. You can delete all your writing from a project folder and still get the most recent version back with a few git commands. You can even go back and see how the project looked a week ago, or six months ago.

You can also include messages to each commit, which is very useful. For example, if you write something but aren’t sure you want to keep it, just do a commit. The section then survives in your commit history even if you delete it from the project later.

Git works best on the command line, which is a great advantage but also has its downsides. The command line is fine to create commits and upload changes. However, if you want to view a commit history, it’s not ideal.

This is why many people like GitHub—a popular online service that offers a web interface for your Git repositories. On GitHub, you can easily view past commits, as well as download your writing to multiple PCs.

Together, Git and GitHub let me control my version history at a granular level. And it’s easy to get my writing on any PC that can run a Bash command line which, these days, includes Windows, Mac, Linux, and Chrome OS machines.

Plain Text Files Make Things Easy

The sublime text editor.
Git can help save your writing, but it can’t make you a better writer.

Git and GitHub do commits on pretty much any file type for writing, although it works best with plain text. If you write in Microsoft Word, it’ll work, but you won’t be able to see your past commits on the command line or in GitHub. Instead, you have to call up a past commit on the command line (called a “checkout”), and then open your Word file. The Word file then looks just as it did when you made the original commit, and you can get back to your current version with another quick command.

If you use Scrivener, that works, too. Scrivener saves files as text, so it also displays past commits on GitHub and the command line. But Scrivener also saves data that’s important to the program, but not to you. In each commit, you’ll end up with a lot of junk that makes it difficult to read.

I use plain text files because that’s all you need to string words together, especially in your first few drafts.

Getting Started with Git

Let’s get into the technical details of how this all works. We’ll start with PC, and then move up to the cloud with GitHub.

To get started, you need the terminal program on macOS or Linux. If your computer runs Windows 10, you have to install Ubuntu or another Linux distribution via the Windows Subsystem for Linux (WSL), which is pretty easy. You can check out our tutorial on how to install the Linux Bash shell on Windows 10. Or, if you use an older version of Windows, you can use Cygwin to get a Bash shell.

Open your terminal and navigate to the folder you want to use as a Git repository. For our purposes, let’s say we have a folder called “MyNovel” in the Documents folder. Note that there’s no space between the words of our Git repo. You’ll make your life easier if you do it this way as Bash doesn’t like spaces, and dealing with them gets confusing.

Next, navigate to the MyNovel folder in the terminal. To do this in Windows 10, the command is:

cd /mnt/c/Users/[YourUserName]/Documents/MyNovel

Any WSL command that interacts with files saved in Windows needs must use /mnt/. Also, note that the lowercase “c” indicates the drive you’re on. If your files are on a “D:/” drive, then you use /d/.

For macOS and Linux the command is much simpler:

cd ~/Documents/MyNovel

From here, the commands are the same.

Now, we have to initialize the MyNovel folder as a Git repository. This command works whether you’re just starting a fresh novel or already have some saved files inside.

git init

Your folder is now a Git repository. Don’t believe me? Type this in:

ls -a

That command asks the computer to list everything in the current folder, including hidden items. You should see something listed towards the top called “.git” (note the period). The hidden “.git” folder is where your document version history is saved. You should never need to open this, but it has to be there.

The First Commit

Before we do our first commit Git wants to know your name and email address. Git uses this information to identify who made the commit, and that information is included in the commit log. For practical purposes, this doesn’t matter since writers are typically flying solo, but Git still requires it.

To set your email and address do the following:

git config --global user.email "[Your email]"

git config --global user.name "[Your name]"

That’s it. Now on to the first commit.

Let’s assume there are three documents in the “MyNovel” folder called: “Chapter1,” “Chapter2,” and “Chapter3.” To save changes, we have to tell Git to track these files. To do this, type:

git add .

The period tells Git to monitor all untracked files in the folder (i.e. files for which you want to create histories). This command also tells Git to prepare any currently tracked files that have been changed. This process is called staging files for commit.

For our purposes, staging isn’t so important, but it can be useful. If you make changes to Chapter 2 and Chapter 3, but only want to commit the changes in Chapter 2, you would stage Chapter 2 like so:

git add Chapter2.doc

This tells Git you want to get the changes in Chapter 2 ready for commit, but not Chapter 3.

Now, it’s time for the first commit:

Git commit -m "This is my first commit."

The “-m” is called a flag, and it tells Git you want to make a commit and tack on a message, which you see between the quotation marks. I like to use my commit messages to mark word counts. I also use them to note special information, such as: “This commit includes an interview with the CEO of Acme Widgets.”

If I’m writing a story, I might include a message that says: “This commit has the new scene where the dog runs away.” Helpful messages make it easier to find your commits later.

Now that we’ve started tracking our documents, it’s time to put our writing in the cloud with GitHub. I use GitHub as an extra backup, a reliable place to look at my document changes, and a way to access my stuff on multiple PCs.

Getting Started with GitHub

The text form to create a new GitHub repository.
You fill out the form to create a new GitHub repository.

First, you need to sign up for a free account on GitHub (you don’t need a paid account to create private repositories). However, you can only collaborate with up to three people on a private repo. If you have a team of five or more working on an article, you need to sign up for a Pro account ($7 per month, at this writing).

After you create your account, let’s make a new repo. Sign in to your account and go to https://github.com/new.

The first thing we need to do is name the repository. You can use the same name you used for the folder on your PC. Under “Repository Name,” type “MyNovel.”

The “Description” is optional, but I like to use it. You can type something like, “My fabulous new novel about a boy, a girl, and their dog,” etc.

Next, select the “Private” radio button, but don’t check the box called “Initialize this repository with a README.” We don’t want to do that, because we already have a repository on our PC. If we create a README file right now, it makes things harder.

Next, click “Create Repository.” Under, “Quick setup—if you’ve done this kind of thing before,” copy the URL. It should look something like this:

https://github.com/[Your GitHub User Name]/MyNovel.git

Now, it’s back to the desktop and our beloved command line.

Push Your Desktop Repository to the Cloud

A PC command line.
Using Git on the command line.

The first time you connect a repo to GitHub, you have to use a few specialized commands. The first one is:

git remote add origin https://github.com/[Your GitHub User Name]/MyNovel.git

This tells Git a remote repository is the origin of “MyNovel.” The URL then points Git toward that remote origin. Don’t get too hung up on the term “origin;” it’s just a convention. You can call it “fluffy” if you want to—origin is just easier since it’s the most common way to use Git.

When you upload new changes with Git, it’s called a “push.” When you download changes, it’s called a “pull” or “fetch.” Now, it’s time to push your first commit to GitHub. Here’s what you do:

git push -u origin master

You’ll be prompted to type your GitHub username and password. If you type your credentials correctly, everything uploads, and you’re good to go.

If you want more security for your GitHub uploads, you can use an SSH key. This allows you to use a single password for the SSH key to upload, so you don’t have to type your full GitHub credentials each time. Plus, only someone with the SSH key can upload file changes.

If you want more info on SSH keys, GitHub has full instructions on how to use them. You can also save your Git credentials on your PC.

That’s it! Now, when you want to commit changes to your files, you can do so with these three short commands (after you navigate to the “MyNovel” folder):

git add .

Translation: “Hey, Git stage for commit all untracked files, as well as new changes to files you’re already tracking.”

git commit -m "1,000 words on the new iPhone review."

Translation: “Hey Git, save these changes alongside this message.”

git push origin master

Translation: “Hey Git, upload the changes to the origin version of this project on GitHub from my master copy on this PC.”

Git and GitHub Bonus Tips

That’s pretty much it, but here are a few extra tips to make your experience with Git and GitHub even better:

View Past Commits

A commit history GitHub's repository interface.
You can use GitHub to see past commits.

To view past commits, go to your MyNovel repository on GitHub. Toward the top the main page, under the “Code < >” tab, you see a section that says, “[X] commits.”

Click it, and you see a list of all your commits. Click the commit you want, and you see your text (if you typed it in plain text and not Word, that is). Everything highlighted in green was new text when the commit was created; everything in red was deleted.

Use the Pull Command

It’s easy to grab a new repository on a different machine. Just navigate to where you want to save the repo on the new machine, such as cd ~/Documents. Then, type:

git pull https://github.com/[Your GitHub User Name]/MyNovel.git

Type your credentials, if prompted, and in a few seconds, you’ll be ready to go. Now, commit new changes, and then send them back to GitHub via git push origin master. When you get back to the PC where you usually work, just open the command line, navigate to your project folder, and type in git pull. The new changes will download, and just like that your writing project is up to date across your devices.

Don’t Cross Streams

Most of the time writing isn’t a team effort and involves only one person. Because of that, this article uses Git in a way that wouldn’t work for a multi-person project. Specifically, we made edits directly to the master version of our novel instead of creating what are called “branches.” A branch is a practice version of the novel where you can make changes without affecting the original master. It’s like having two different copies of your novel existing in parallel with neither affecting the other. If you like the changes in the practice branch you can merge them into the master version (or master branch). If you don’t want to do that, that’s fine too. Just throw away the practice branch.

Branches are very powerful, and using them would be the primary workflow with multiple writers on a single project. Solo writers don’t really need to use branches, in my opinion—as long as you don’t make differing changes to the master branch at the same time on multiple PCs.

For example, you should complete your work on your desktop, do your commits, and then push the changes to GitHub. Then go to your laptop and pull all the new changes down before you make any further edits. If you don’t, you might end up with what Git calls “conflicts.” That’s when Git says, “Hey, there are changes in GitHub and on this PC that don’t match. Help me figure this out.”

Sorting your way out of a conflict can be a pain, so it’s best to avoid it whenever possible.

Once you get started with Git, there are tons of things you can learn, such as branching, the difference between a fetch and a pull, what GitHub’s pull requests are, and how to deal with the dreaded conflict.

Git can seem complicated to newcomers, but once you get the hang of it, it’s a powerful tool you can use to manage and store your writing.

Ian Paul Ian Paul
Ian Paul is a freelance writer with over a decade of experiencing writing about tech. In addition to writing for How-To Geek, he regularly contributes to PCWorld as a critic, feature writer, reporter, deal hunter, and columnist. His work has also appeared online at The Washington Post, ABC News, MSNBC, Reuters, Macworld, Yahoo Tech, Tech.co, TechHive, The Huffington Post, and Lifewire. His articles are regularly syndicated across numerous IDG sites including CIO, Computerworld, GameStar, Macworld UK, Tech Advisor, and TechConnect.
Read Full Bio »