In this tutorial, we'll show how you can work with branches using only github and colab.
To complete this tutorial, you'll need a google account (with access to a google drive) and a github account.
You'll also need an nbdev
project in github. If you don't, please take a look at this tutorial
.
- Navigate to your project in github,
- click the "Switch branches" button,
- enter a new branch name and
- click "Create branch"
Add a section to nbdev_colab_projects.ini for your new branch
Here's an example nbdev_colab_projects.ini
that uses the project name "nbdev_colab_helper_wip" for the new branch "change-dflt-branch-instructions2":
[DEFAULT]
project_parent = /content/drive/My Drive/Colab Notebooks/github
git_user_name = **changeme**
git_user_email = **changeme**@gmail.com
git_user_password = **changeme**
[nbdev_colab_helper]
git_url = https://github.com/pete88b/nbdev_colab_helper.git
git_branch = master
[nbdev_colab_helper_wip]
git_url = https://github.com/pete88b/nbdev_colab_helper.git
git_branch = change-dflt-branch-instructions2
Run setup_project
Run these setup steps in colab (feel free to use an existing colab helper notebook if you have one).
Using the above config, I can find the new branch in google drive: /content/drive/My Drive/Colab Notebooks/github/nbdev_colab_helper_wip.
You can now edit files and (using your colab helper notebook) build your library, run tests etc.
When your ready to push to github, it's a good idea to check what has changed by running:
!git status
On branch change-dflt-branch-instructions2
Your branch is up to date with 'origin/change-dflt-branch-instructions2'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: 00_core.ipynb
modified: docs/tutorial.html
modified: tutorial.ipynb
no changes added to commit (use "git add" and/or "git commit -a")
if you want to push all changes, you can:
commit_message = 'minor changes to tutorial'
git_push(project_config['git_branch'], commit_message)
or you can push changes to just 2 files with something like:
!nbdev_install_git_hooks
!git add docs/tutorial.html
!git add tutorial.ipynb
git_branch = project_config['git_branch']
!git commit -m "minor changes to tutorial"
!git push origin $git_branch
You should now be able to go back to github and create a pull request.
Once you have finished working with your new branch in colab, it might make sense to delete it from your google drive to
- save a little space on your drive and
- make it possible to use the same project name again
I'll probably use the "nbdev_colab_helper_wip" project name for whatever branch I'm currently working on.