Git is an essential tool for developers, and Ubuntu is one of the most popular Linux distributions. Whether you’re working on an open-source project or collaborating with a team, cloning a Git repository is a fundamental skill.
In this tutorial, you’ll learn how to clone a Git repository on Ubuntu using simple terminal commands.
✅ Prerequisites
Before you begin, make sure:
- Git is installed on your Ubuntu system.
- You have the URL of the Git repository you want to clone.
🔹 Step 1: Install Git (if not already installed)
To check if Git is installed, run:
git --version
If Git is not installed, install it using:
sudo apt update
sudo apt install git -y
🔹 Step 2: Choose or Create a Directory
Navigate to the folder where you want to clone the repository:
cd ~/Documents/projects
Or create a new one:
mkdir my-repos
cd my-repos
🔹 Step 3: Clone the Repository
Use the git clone
command followed by the repository URL:
git clone https://github.com/username/repository.git
Example:
git clone https://github.com/octocat/Hello-World.git
This creates a folder named Hello-World
and downloads the project files into it.
🔹 Step 4: Navigate into the Cloned Repository
cd repository-name
Example:
cd Hello-World
Now you’re inside the cloned repository and ready to start working.
🔐 Optional: Use SSH Instead of HTTPS
If you’ve set up SSH keys with GitHub or GitLab, use the SSH link instead:
git clone gi*@gi****.com:username/repository.git
✅ Summary
Task | Command |
---|---|
Install Git | sudo apt install git -y |
Clone a repository (HTTPS) | git clone https://github.com/user/repo.git |
Clone a repository (SSH) | git clone gi*@gi****.com:user/repo.git |
Enter repo directory | cd repo-name |
🚀 Final Thoughts
Cloning a Git repository on Ubuntu is quick and easy once Git is set up. Whether you’re contributing to open source or managing your own code, this workflow helps you stay productive in a Linux environment.