Start an Open-source Project on GitHub

There are about 80 Xojo-related open-source projects that I am tracking on the Xojo Dev Center: Open-Source Projects. I often have people ask me how they can make their own cool libraries and projects available on GitHub, so here’s a short tutorial.

Create a GitHub Account

If you don’t already have a GitHub account, you’ll need to create one. GitHub is the most popular place for hosting open-source projects and it is entirely free. As its name suggests, GitHub uses the Git source control system for storing the project source and managing updates. It also has a built-in wiki for documentation and an issue tracker.

The way GitHub works is that you’ll add your project, which is then available for anyone to download and use. In addition, others can submit changes to your project in the form of “pull requests”. These are perhaps enhancements or bug fixes that you can review and choose to merge into the project if you want.

Create Repository

Now that you have a GitHub account, you’ll want to go to your GitHub home page and click the “New Repository” button. A repository is essentially where your project is stored. You’ll want a separate repository for each project. This is what the new repository form looks like:

Be sure to come up with a catchy “repository name” and always include a description. You’ll want to leave “Public” selected as it’s not really open-source if it’s not public – and you actually have to pay to host private repositories on GitHub.

I always check “Initialize this repository with a README”, which adds an empty README file. This is where you’ll briefly describe the project and how to use it (using Markdown).

You should also select “Xojo” for the gitignore setting. This identifies the project as using the Xojo programming language, which helps with searches and also marks the “uistate” file so that it is not included in the project.

Lastly, you’ll need to choose a license. For most projects, I recommend the MIT License, which essentially allows anyone to use your code however they want.

Click the Create Repository button to create the repository.

Clone the Repository to your Computer

Now that the repository is created on GitHub, you’ll want to “clone” it to your computer. This copies the repository files to a folder on your computer to you can modify its files. Of course, the only files in the repository will be LICENSE and the empty README.md, but it is still necessary to do the clone so that you can create the folder where you will then add your Xojo code.

In order to clone, you’ll want to use a Git client application. There are many to choose from, but two free ones are the official GitHub Desktop and Atlassian SourceTree. Personally I prefer SourceTree, but the GitHub Desktop is a bit simpler so that is the one I’ll show here.

Download GitHub Desktop: https://desktop.github.com

Start GitHub Desktop and click “Sign into GitHub.com”.

On the Configure Git page, enter the name and email you want to use to identify your commits.

Click Finish on the next page to show the main screen:

On this screen you have the option of creating new repositories or cloning a repository. Since we already created a repository online in the previous section, you want to select “Clone a Repository”. In the list, choose the repository you created above, choose your local folder location (Choose…) and click Clone.

You now have a folder on your disk where you can add your Xojo project.

Note: If you are using another client, you will choose its “clone a repository from URL” feature and then provide the URL shown in the “Clone or Download” button on the repository page.

Add Your Xojo Project Code

Start Xojo and open the project you want for the repository you cloned. Click “Save As”, make sure the Format is “Xojo Project” and choose the folder you created when you did the checkout. You’ll want to use the “Text Project” format as that is what works best with Git because it allows people to view source online and makes it possible to precisely track changes.

Note: Any Xojo edition can open projects in Xojo Project format, but the Xojo Free edition and Xojo Lite edition cannot save in Xojo Project format. Contact us if you’d like to upgrade.

Go back to GitHub Desktop and you’ll now see all the Xojo files appearing in the list as “changed files”. (For my test I used Examples/Database/SQLite/SQLiteExample.)

You now need to “Commit” these changes. By default they are all checked so you can enter a brief summary (for the first commit, often “Initial Commit.” is used) and then click the “Commit to master” button.

This marked the files as committed in your local repository, which is needed before you can push the changes up to the online repository. Generally speaking you want to commit things after you have made changes that you want to track. You don’t need to immediately push the changes up to the server (online repository) each time, however.

But for this initial commit you do want to push it out to the server, so click the button in the toolbar that says “Push origin”.

If you go back to the GitHub repository online and refresh the page you’ll now see the files have been committed:

Sharing Your Project

Your project is now publicly available on GitHub for you to share with the world. All you need to do now is give people the URL! Definitely at least share the URL with me so I can add it to the Open Source Projects page in the Xojo Dev Center.

However, one other thing you should do on the project is click the “Add topics” link under the project description near the top of the page and add some tags. At the very least, add a tag for “Xojo”, but also add tags for whatever other technologies are relevant to your project. This will make it much easier for people to find your project when they search.

Changing and Updating Your Project

You’ll likely be continuing to change your project to fix bugs and add features. Each change you make shows up in GitHub Desktop where you can commit it and then push it to the server.

As an example, you should also make sure you update the README.md file to actually have a bit more description of your project and how people can use it. On your computer, open README.md in a text editor (or even better, a Markdown editor if you have one — I use Markdown Pro). You can learn more about Markdown here: GitHub Markdown Guide

Save the file and the go to GitHub Desktop to see that it shows as changed. With the file selected in GitHub desktop you can see that it shows you what has changed with the new content identified. This also works with source code and is why you want to use the Xojo Project text file format — you’ll be able to see exactly what code you’ve changed.

You can now Commit this change (always add Summary text so you know the reason for the change!) and then Push it to the server (Push origin).

Using or Cloning Other Repositories

Now that you’ve published your project, anyone can use it. And don’t forget that you can also use other people’s repositories. In both cases you’ll want to click the “Clone or Download” button on the repository page.

For simple usage where you just want to grab the current version of the repository you can then click the Download ZIP button. Once downloaded, unzip the file and then open the project in Xojo where you can use it or copy/paste it into your own projects (review the license agreement before you use projects, of course).

You’ll want to clone a project when you want to manage it using GitHub Desktop (or your GitHub client of choice). This allows you to fetch and pull updates from the online repository and also allows you to make your own changes and push them up to the server where the repository owner will get them as pull requests. The owner can then review your changes and decided whether they want to incorporate (pull) them into the project.

GitHub is Great

I look forward to seeing new Xojo projects appearing on GitHub! This article just scratches the surface of what GitHub does and also only touches lightly on the concept of source control in general. If you’d like to use Git for source control, but don’t want to make your projects public you might also want to check out Atlassian BitBucket which offers free Git hosting for both private and public repositories.

To learn more about Git in general, watch these webinars: