Ubuntu – How to upload a file from Google Colab to GitHub or Kaggle

githubgoogleupload

As you all know we are able to load a file from a site such as Kaggle and GitHub to Google Collab, we apply the bellow code to download from other sites into Google Collab:

wget nlp.stanford.edu/data/glove.6B.zip

but I am very curious to know if I am able to upload a saved file in Google Collab to another site through some commands like the above? I mean I can do it manually in some multiple steps but please let me know if there are some commands to upload a file directly from Google Collab into another site such as GitHub.

Best Answer

To add a file to a Git repository and upload it to GitHub please refer to its official help articles Creating a new repository, Cloning a repository, and Adding a file to a repository using the command line. I’ll include the most important steps below:

  1. Install Git:

    sudo apt install git
    
  2. Create a repository on GitHub.

  3. Import (or “clone”) the Git repository and enter its top directory:

    git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
    cd YOUR-REPOSITORY
    
  4. Place the desired file into the repository directory (or one of its sub-directories) e. g. by moving or copying it from another place or downloading it from an external resource.

  5. Add the file to the Git repository:

    git add my-file
    
  6. Commit the changes to the repository:

    git commit --message="Add my-file"
    
  7. Upload (or “push”) the committed changes to the upstream repository (here: at GitHub):

    git push
    

Obviously you don’t need to repeat steps 1–3 if you did them before.

Related Question