DEV Community

Cover image for Adding Colab Notebooks to Github using Git
Rahul Bordoloi
Rahul Bordoloi

Posted on

4 2

Adding Colab Notebooks to Github using Git

Ever thought of pushing your Colab Notebook into your Github Repository Directly? Yes, It's possible and it's an anomaly of how we do it locally.

Firstly, Initialize an empty git repository as -

!git init
Enter fullscreen mode Exit fullscreen mode

Then, add your data to your Global Config-Files,

# Add your email to the global config-file
!git config --global user.email <your-email-add@email.com>

# Add your email to the global config-file
!git config --global user.name <your-github-username>
Enter fullscreen mode Exit fullscreen mode

Then add your files to the repo using -

!git add .
Enter fullscreen mode Exit fullscreen mode

NOTE: !git add. would add all the files and folders from your current directory. We can selectively select the files we want to add too by using -

!git add <file-name/directory-name>
Enter fullscreen mode Exit fullscreen mode

Then commit the added files with a message -

!git commit -m "Colab Commit"
Enter fullscreen mode Exit fullscreen mode

Now, Adding our remote repository into our colab system,

!git remote add origin https://<your-github-username>:<your-github-password>@github.com/<your-github-username>/<your-repository-name>.git
Enter fullscreen mode Exit fullscreen mode

Note: If we've activated 2FA Security on your account, then we must add our personal-access-token instead of our password which is available in Settings -> Developer Settings -> Personal Access Token ie replace <<your-github-password> with <personal-access-token>

And at last to push our committed files into our repository-

!git push -u origin master
Enter fullscreen mode Exit fullscreen mode

Note: If any error occurs in this step regarding push, Try out

!git push -u origin master --force
Enter fullscreen mode Exit fullscreen mode

Troubleshooting -

If you get errors with origin like fatal: remote origin already exists, try out -

!git remote rm origin
Enter fullscreen mode Exit fullscreen mode

For any queries, mail me at - mail@rahulbordoloi.me

Also, check out my Gist for the same -

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Thank You!

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

Collapse
 
hb profile image
Henry Boisdequin

Cool and out of the box! Thanks!

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more