How to integrate Code Ocean with an existing GitHub workflow

A lot of us use GitHub to collaborate and push changes frequently. However, if you want to share the repo with someone new to the project, that person has to download and install everything that original collaborators already did, which may or may not be trivial. With Code Ocean you can share your work and anyone new to the project can run your results right away.

Here is a tutorial on how to add a Code Ocean compute capsule as another remote Git repo, so that when you are ready to push to GitHub, you can push to Code Ocean at the same time without having to deal with the sync later. Again, please comment directly below if you have questions or issues!


This tutorial assumes that you already have a local repo synced with the “master” branch of a GitHub repo. We use GitHub as an example but the same steps can be applied to repos on GitLab, BitBucket, etc. by replacing the urls.

The purpose here is to demonstrate how to add a Code Ocean capsule as a remote repo, so that whenever you push to your GitHub repo, the same content also gets pushed to a Code Ocean capsule. The entire set up takes ~ 5min, and after it is done, all you need to do when you push to both repos is

git push all master

Here are the 12 steps to get it set up (steps 5-9 are activities in Code Ocean that are recommended but optional).

  1. cd {local_repo_name}
  2. Create a blank capsule and DISCARD ANY EDIT
  3. git remote add all {code_ocean_git_repo}
  4. git push all master
  5. Edit environment
  6. Edit metadata
  7. Edit ‘run’ file
  8. After a successful run, commit all the files
  9. git pull all master
  10. git remote set-url --add --push all {original_github_repo}
  11. git remote set-url --add --push all {code_ocean_git_repo}
  12. git push all master

More verbose explanations:

The example GitHub repo is, which is forked from

  1. Enter the local repo

cd 4Dsegment

  1. Verify the current remote to be from GitHub (if you use 2-factor authentication, you may want to use the personal access token to authenticate your private remote). It may prompt you for your GitHub (or other repo Git credentials. Not to be mixed up with the ones from Code Ocean!).

git remote -v

origin (fetch)
origin (push)

git pull

  • Already up to date.
  1. Then we create a new capsule and leave it blank (DO NOT select an environment or edit ANYTHING in the capsule). DISCARD the edit in “metadata” so there is nothing to commit by clicking on the downward arrow on the right hand side of the file edited. If you accidentally edited anything, just click on “Discard Changes” until it’s unmodified.

The capsule should look like this with all the folders empty on the left with green check marks and nothing to commit on the right.

  1. ** Add the Code Ocean capsule url locally as a remote repo called “all”. It can be any name you’d like, but we call it “all” because later when we push to it, it updates all the remote repos (e.g. GitHub and Code Ocean).**

    Get the capsule git url from Capsule -> Clone via Git

    Click on “Copy” next to the url

    Then we add the capsule url locally as a remote repo called “all”. It can be any name you’d like, but we call it “all” because later when we push to it, it updates all the remote repos (e.g. GitHub and Code Ocean).

git remote add all

Verify remote repos again:

git remote -v

all (fetch)
all (push)
origin (fetch)
origin (push)

  1. Push the existing local repo to the remote capsule repo (all) on the master branch. (Here you may see a prompt for your Code Ocean account and password.)

git push all master

Enumerating objects: 2094, done.
Counting objects: 100% (2094/2094), done.
Delta compression using up to 8 threads
Compressing objects: 100% (681/681), done.
Writing objects: 100% (2094/2094), 6.74 MiB | 1.48 MiB/s, done.
Total 2094 (delta 1386), reused 2094 (delta 1386)
remote: Resolving deltas: 100% (1386/1386), done.
* [new branch] master -> master

  1. (Optional) These steps are strongly recommended but optional. If you skip them, you are still able to push to both remote repos, but you still need to go through them later in order to run the code in Reproducible Run from the capsule.

If you want to make sure the capsule runs the code and the description makes sense, we need to do the following 4 things in the capsule.

  • Edit the environment using the environment editor
  • Edit metadata using the metadata editor
  • Create a run file
  • After a successful reproducible run, commit all the files.

Then we need to update the GitHub repo with the content we just edited from Code Ocean by pulling from the Code Ocean remote repo to local first.

git pull all master

  1. Add the original GitHub repo url as well as the Code Ocean capsule git url (again) to the push command for the remote repo called “all”, so the updates will get pushed to both remote branches at the same time

git remote set-url --add --push all
git remote set-url --add --push all

  1. Verify the remote repos

git remote -v

all (fetch)
all (push)
all (push)
origin (fetch)
origin (push)

  1. Test that we can push the local repo to all remote repos.

git push all master

  1. From this point on, you can make edits locally, commit it, and then push to both repos at the same time!

For example, to create an empty new file called “newtest” and push to both repos.

touch newtest
git add .
git commit -m “added new empty file”
git push all master

Voila! Pushing to 2 repos with one line!