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 -
Then, add your data to your Global Config-Files,
# Add your email to the global config-file !git config --global user.email <firstname.lastname@example.org> # 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 .
!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
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
If you get errors with origin like
fatal: remote origin already exists, try out -
!git remote rm origin
For any queries, mail me at - email@example.com
Also, check out my Gist for the same -