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
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>
Then add your files to the repo using -
!git add .
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>
Then commit the added files with a message -
!git commit -m "Colab Commit"
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
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
Note: If any error occurs in this step regarding push
, Try out
!git push -u origin master --force
Troubleshooting -
If you get errors with origin like fatal: remote origin already exists
, try out -
!git remote rm origin
For any queries, mail me at - mail@rahulbordoloi.me
Also, check out my Gist for the same -
Thank You!
Top comments (1)
Cool and out of the box! Thanks!