How to Upload Github Using Jupyter Notebook
This article is a Git 101 for Jupyter users. Advanced Git users might want to check out integration workflow, real world examples and FAQs for making notebooks play nicely with GitHub.
This is a hands on tutorial for beginners & is meant to exist comprehensive. Experience free to skip a section if you're already familar with it. At the finish you lot'll be able to,
- Push button your notebooks to a GitHub repository in cloud
- Starting time versioning your notebooks
- Acquire how to revert to a specific notebook version
- Review Jupyter notebook pull requests on GitHub
- Become feedback & hash out notebook changes with your peers
- Easily share your notebooks for others to view
Create GitHub Account
If you don't have a GitHub business relationship please create one hither.
Setup Git
- Download and install the latest version of Git.
-
Setup your proper noun & email in git by running following commands on last
>> git config --global user.proper name "Mona Lisa" >> git config --global user.email "email@instance.com" - Connect your local git client with GitHub past caching your countersign.
Create New Repository
A GitHub repository is like your supercharged folder in the cloud. Y'all can store files (notebooks, data, source code), wait at historical changes to these files, open up issues, discuss changes and much more. People typically create 1 repository per project.
Let'due south go ahead & create a repository on GitHub. Once created, you'll see a page like below, copy the highlighted repository URL.
Clone Repository
Let's clone the GitHub repository on our automobile by running following on the terminal. It volition create projectA directory on our auto which is linked to amit1rrr/projectA repository on GitHub.
>> git clone https://github.com/amit1rrr/projectA.git Cloning into 'projectA'... warning: You appear to have cloned an empty repository. Push Notebooks to GitHub
Our repository is empty right at present, allow's push some notebooks to information technology. We copy two notebooks to the directory where we cloned projectA repository,
>> cp /some/path/analysis1.ipynb /path/of/projectA/ >> cp /some/path/scratch.ipynb /path/of/projectA/ Allow's say we desire to push analysis1.ipynb to GitHub. We first need to tell local git client to start tracking the file.
>> git add analysis1.ipynb You tin cheque which files are being tracked with git status,
You tin can run across that analysis1.ipynb is under "Changes to be committed:" and so information technology'south existence tracked past our local git client. Now permit'south commit the changes,
# -thou flag is used to provide a human friendly message describing the alter >> git commit -m "Adds customer data analysis notebook" Commit simply creates a checkpoint that you can revert to at any time. Allow's push this commit to GitHub.
Now you can visit the repository page on GitHub to encounter your commits.
Develop in a Branch
Say you are working on a large project spanning multiple days, but you demand to periodically push work in progress commits. The fashion to practice that is past creating a feature branch.
Each repository has a default branch (typically master or main) that stores near upwards-to-date versions of completed work. Each member of your team can create their ain feature branches to store their WIP commits. When their work in a feature branch is ready to be shared they can create a pull request for peer review & later on merge the feature branch into master. Let's unpack that with physical steps.
Say I'm about to starting time working on a new projection to analyse client data. First, I will create a new branch,
>> git checkout -b customer_data_insights And then I'll create/edit some notebooks & other files to do the bodily analysis. When I'm gear up to commit my WIP, I'll do the usual git add, git commit, git button. At git push button you will come across following error since the co-operative does not exist on GitHub yet.
Only button the branch kickoff past copying the command shown in error,
>> git push --gear up-upstream origin customer_data_insights And then exercise git push to push your commits to this newly created co-operative.
Create Pull Request
Let'southward say you've been working on characteristic branch for a while, and information technology'southward set for prime number time. Most probable, you lot'd want to beginning share it with your peers, get their feedback earlier merging it into master branch. That's what pull requests are for.
You can create pull requests from GitHub UI. Get to your Projection page -> Pull requests tab -> click "New pull request".
Choose which branch you'd similar to merge into main. Verify commits & list of files changed. Click "Create pull request".
On the next page provide title & draw your changes in brief, hit "Create pull request" again.
Review Notebook Pull Request
GitHub pull request are fantastic for peer review every bit they permit you encounter changes side-by-side & annotate on them. But in case of Jupyter, GitHub shows JSON diffs which are really hard to read (see below).
You can use ReviewNB to solve the notebook diff'ing problem. It shows you rich diffs & lets you comment on any notebook cell to talk over changes with your team.
Once your changes are canonical you tin can merge them from GitHub UI.
Or run git merge + git button from command line,
Revert to a specific notebook version
If you want to temporarily go back to a commit, checkout the files, and come back to where you are then you tin merely checkout the desired commit. At the end run "git checkout master" to go back to the electric current state.
If you want to really revert to an onetime land and make some changes in that location, you can offset a new branch from that commit.
>> git checkout -b onetime-country f33939cd63004e3e67b111f7bcb350ffd2b0608a You lot tin also browse old commits on GitHub by going to Your project page -> Commits. Open the desired commit and click "View File" to see the notebook status at that commit.
When you lot browse notebooks in your repository on GitHub it renders them as HTML. And so it's very convenient to share read-only links to the notebook like this one. If information technology'southward a private repository, the person yous are sharing the link with needs to take a GitHub account and accept permission to access your repository.
For security reasons, GitHub does not run any Javascript in the notebook. You can utilize nbviewer or ReviewNB if your notebook contains interactive widgets and such.
Conclusion
If you are new to Git, it tin can accept some time to get used to all the commands. Merely it's a proven way of collaborating on software projects & is widely used in data science work also. You lot tin can combine it with ReviewNB to remove some of the kinks in the workflow.
Happy Hacking!
sanchezpicarmention.blogspot.com
Source: https://blog.reviewnb.com/github-jupyter-notebook/
0 Response to "How to Upload Github Using Jupyter Notebook"
Post a Comment