Introduction: How to Backup Your Arduino Sketches for Free Using Bitbucket

About: Hey everyone! My name is Brian and thanks for checking my Instructables. I'm a software developer by trade but I've recently gotten into Arduino development after discovering the esp8266 chip, a WiFi enable…

Hello everyone!

In this instructable I'm going to show you how to backup your Arduino sketches for free using Bitbucket.

Bitbucket is source control service which is very similar to Github. It allows for storing of projects or code which can be accessed from other machines, or viewed directly on their website.

I do think Github is easier to use, especially setting up for the first time, but Github does not allow you to make the code private without signing up for one of their paid plans, which start at $7 a month.

Normally I'm all for Open Source, but this is mostly going to be used for backuping Arduino projects that could contain passwords or keys that you do not want to make publicly accessible.

There is a few setup steps, which I'll go through in this Instructable, that only need to be done the first time. After you are set up backing up your code will only take seconds. Setup will take roughly 10 minutes.

Step 1: Why Is This Important?

If your hard drive was to break right now, how many Arduino sketches would you lose? Lots of things could go wrong where you are left wishing you had your sketches backed up, such as losing your laptop or accidentally deleting something.

Another big advantage is it gives you access to your sketches even when you are not on your computer and you can even view your code via their website.

As mentioned, this setup is completely free and will only take a few minutes, so there really is no reason not to do it!

Step 2: Accounts and Installation

  • You will need to create an account on
  • Then download the SourceTree application from
  • Open the SourceTree installer
  • Sign in using your newly created Bitbucket account.
  • When you get the "Clone a Bitbucket repository" part, you can click "Skip Setup".
  • When it asks about loading your SSH key, click "No" (unless you have one!)

Step 3: Creating a SSH Key

The following are steps for creating an SSH key, this is so Bitbucket can be sure that only people using keys that it knows about should be allowed access your account. This will only need to be done when setting up for the first time.
  • In SourceTree, click Tools -> Create or Import SSH Keys
  • Click Generate and move your mouse in the area to generate a random key
  • Type in a passphrase for the key
  • Click Save public key and save your public key
  • Click Save private key and save your private key, you will need this later
  • Copy your public key to your clipboard (the one in the large text box)

  • Go to and click on your account on the top right of the screen
  • Click Bitbucket Settings
  • Under "Security", click SSH keys
  • Click Add key
  • Enter whatever label you'd like and then paste the key from your clipboard into the Key box
  • Click Add Key

If you have any questions on any of this please let me know in the comments and I will try explain it better!

Step 4: Add Your Code Locally to SourceTree

Next we are going to add the code locally to SourceTree.

  • In SourceTree, click Clone / New
  • Click the Create New Repository tab
  • For Destination Path navigate to the Arduino folder where your sketches are (for me it was under My Documents)
  • This will include all files in that folder, including libraries which you may want to not backup. If you right click on one of the files under libraries and click Ignore ... and then click on Ignore everything beneath libraries
  • Then click Stage All
  • Type in a commit message in the text box down the bottom. Its normally good to make this a descriptive message of what you are doing.
  • Click Commit

We are almost there... I promise!

Step 5: Configuring a Remote Repository

At this point the code is still only stored locally on your machine, but we want it to be backed up on Bitbucket. We need to configure a remote repository (basically somewhere to store the code on Bitbucket). To do that we need to do the following.

  • Go to
  • Click Repositories and then Create repository
  • Type in a name for your repository (Arduino Backup or something). Make sure you tick the "This is a private repository" checkbox!
  • Then click Create repository
  • In the top right of the screen, copy the SSH url for your project to your clipboard

  • Back in SourceTree, click on Repository -> Add Remote
  • Click Add
  • Check the Default remote checkbox
  • Paste in the SSH Url into the URL / Path box
  • Click Ok and then Ok again

Step 6: Pushing to the Remote Repository for the First Time

This is the final hurdle, we are so close :)

We now want to push the code to the remote repository on Bitbucket. Github does a much better job of handling all this setup, but I don't think avoiding doing this instructable is worth $7 a month!

  • In SourceTree, click Push and Push again
  • A message will pop up Launch SSH Agent, click Yes
  • This will launch a tool call Pageant in your toolbar (it's a computer with a hat on it, see the included photo)
  • Right click on Pageant and click Add Key
  • Navigate to the private key you saved earlier
  • Enter your passphrase from earlier and click Retry
  • This should push your code up to Bitbucket! Refresh the repository page from earlier and your sketches should be under the Source section

Step 7: Now Lets See How It Easy It Should Work!

This has been a lot more complicated than I would have liked to be! But once it's setup it's much easier to use going forward. Let's do a really quick demo of how it works from here on in.

  • Create a new sketch in the Arduino IDE and save it. (or change an existing one).
  • Go to SourceTree
  • If you created a new sketch you will need to click the Stage All button
  • Type a commit message down the bottom and check the Push change immediately to origin/master checkbox
  • Click Commit

And that's it! Your new changes will be backed up to Bitbucket!

Hopefully you find this useful and as always if you have any questions please let me know.