Open In App

How to Install and Use Git in Google Colab?

Last Updated : 03 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Colab or Colaboratory is a cloud-based Jupyter environment from Google. It was developed by the Research Team at Google to build and test machine learning or deep learning algorithm that requires high computational power. It is available to anyone with a Google account free of cost with some limitations on GPUs and TPUs. Git is a free and open-source distributed version control system created by Linus Torvalds in 2005.  Its features include support for distributed, non-linear workflows, branching, pull requests, merging, tracking history, and a very easy learning curve.

In this article, we will discuss how to use git in Google Colab to clone a private repository, commit some new changes and push these changes to the remote repository. The process is simple and straight word if you are familiar with git. Fortunately, Google Colab comes with git pre-installed. So, all we need is to run some shell commands by using the ! operator.

Installation of Git in Colab

Step 1: Verify the git installation on the machine by running

!git version

Verifying-git-installation

 

Step 2: Update git configuration settings by adding your email and username to the commit.

!git config –global user.email “email”

!git config –global user.name “username”

Updating-git-configuration

 

Step 3: Before cloning the repository, generate a personal access token by visiting https://github.com/settings/tokens  Make sure to give the required privileges to the token.

New-personal-access-token

 

Personal-access-tokens

 

Step 4: Clone the required repository using the PAT.

!git clone https://git_token@github.com/username/repository.git

Cloning-required-repository

 

Files

 

Step 5: Change the working directory to the newly cloned folder by using the % operator.

%cd folder_name

Changing-working-directory

 

Step 6: Now, we can create, update or delete any file in our cloned repository. But for now, I am creating just a dummy readme file.

!echo “# Some dummy text” >> new.md

Dummy-file

 

Step 7: Commit the new file and push the changes to the main branch.

!git add .

!git commit -m “relevant message”

!git push origin branch_name

Commiting-new-file

 

Step 8: Verify the commit in the git logs or visit the repo on Github/GitLab.

!git log

Verifying-commit

 

Visiting-repo

 

Verified-commit

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads