-
Notifications
You must be signed in to change notification settings - Fork 128
Guide to using DEA Notebooks with git
If you're developing notebooks for dea-notebooks
, or reviewing someone's work there, it's useful to work with Git to track and push changes.
This guide covers how to get set up with Git, along with how to use Git for development and review.
The guide is currently split into two sections:
On launch, the sandbox is pre-populated with notebooks from the dea-notebooks
repo.
Specifically, with copies of the notebooks in the DEA_Sandbox
folder on the master branch.
However, for development and review, you'll need your own copy of the dea-notebooks
repo that won't be overwritten by the sandbox's launch behavior.
To get your own copy of the repository:
-
Open a terminal from the JupyterLab Launcher (click the "+" New Launcher button on the top-left of JupyterLab, then click "Other > Terminal")
-
Make a new directory to work in by typing:
mkdir dev
-
You should see the
dev
directory appear in the file structure. Enter the new directory by typing:cd dev
-
Clone the notebooks repository by typing:
git clone --depth 1 https://github.com/GeoscienceAustralia/dea-notebooks.git
-
Enter the notebooks directory by typing:
cd dea-notebooks
-
Start a new branch (using
develop
as the base) by typing the command below (replacebranch_to_work_on
with a name of your choice)git checkout -b branch_to_work_on develop
-
See which files you've changed by typing:
git status
-
See the changes to notebooks by clicking the
git
extension button in the notebook -
Add the files you want to commit by typing
git add
followed by the filenames you want to add or--all
to add everything -
Commit the files with a message by typing:
git commit -m "Simple commit message"
-
Push your changes by typing
git push
- If this is the first push from this branch, you'll need to type:
git push --set-upstream origin branch_to_work_on
-
Enter your Github username and password to complete the push. If you do not have a Github account, create one here.
Important: If this is your first time using
dea-notebooks
, you will probably receive aremote: Permission to GeoscienceAustralia/dea-notebooks.git denied
error. To resolve this, an existing member ofdea-notebooks
will need to invite you to the repository (Settings > Collaborators and Teams > Search by username, full name or email address > Add Collaborator
)
Work can be added to the develop
branch using a "pull request". A pull request will take all changes made to a branch and merge this into another branch (typically, develop
). Because we don't always want all changes on a branch to be merged in, we need to first create a temporary pull request branch containing only the changes we want.
-
Avoid merge conflicts later on by getting the latest version of the
develop
branch:git checkout develop git pull
-
Create a new temporary branch that is an exact copy of
develop
. This is where the files you want to publish will be placed (changetemp_branch_name
to a simple name of your choice that describes the changes you are making):git checkout -b temp_branch_name develop
-
Copy the files (e.g.
Scripts/dea_datahandling.py
) you want to publish from your main branch (e.g.branch_to_work_on
that we created above) to this new temporary branch:git checkout branch_to_work_on -- Scripts/dea_datahandling.py
-
Push the temporary branch up to Github so we can create a pull request:
git push
-
When you’ve pushed your changes and are ready for feedback, visit the pull requests page on the DEA Notebooks repository:
https://github.com/GeoscienceAustralia/dea-notebooks/pulls
-
The name of the temporary branch you just pushed should appear in yellow. Click the green "Compare and make pull request" button to the right.
-
This will take you to the 'Open pull request' page.
-
Add a description of your changes, and select people you’d like to review it
-
To make changes/updates/edits to someone else's pull request, first check out the branch you want to edit (e.g.
pull_request_branch
):git checkout --track origin/pull_request_branch
-
Commit and push any changes you make, which will become part of the open pull request
-
You can update your branch by checking it out, then typing
git pull
- You should regularly do this for the
develop
branch
- You should regularly do this for the
-
To get the latest updates from the
develop
branch back into your own branch, follow the steps below (this can also be useful to check for conflicts between your branch anddevelop
):git checkout develop git pull git checkout branch_to_work_on git merge develop
-
When the text message pops up to give the merge commit a name, it will be in the Vi editor. To accept the default message, hit
Esc
on your keyboard, followed by:wq
The above instructions should work for setting up Git on both the DEA Sandbox and the NCI (via the Virtual Desktop Infrastructure or VDI). However, there are some important things to keep in mind:
- To get started with
dea-notebooks
using git on the NCI, the first step is to clone this repository to a suitable location. This will most likely be a location you can access on the VDI, so you can easily work with your notebooks. Note that this repo is likely to become quite large, so make sure you have enough space in the location you clone the repository to (i.e. probably not your home directory, but a directory on/g/data/
should be perfect). - If you haven't used Git on the VDI before, you will need to set up some SSH keys before you will be able to clone the repository. To set up the SSH keys, follow the instructions here to generate an ssh key pair in your home directory on the vdi. You will need to generate the key, register it with your
ssh
agent, and then add the newly generated id_rsa.pub public key to your GitHub account.
Updating this wiki: If you notice anything incorrect or out of date in this wiki, please feel free to make an edit!
License: All code in this repository is licensed under the Apache License, Version 2.0. Digital Earth Australia data is licensed under the Creative Commons by Attribution 4.0 license.
Contact: If you need assistance with any of the Jupyter Notebooks or Python code in this repository, please post a question on the Open Data Cube Discord chat or on the GIS Stack Exchange using the open-data-cube
tag (you can view previously asked questions here). If you would like to report an issue with any notebook, you can file one on Github.