Cloning a Git repository is one of the first steps in working with a project from GitHub or another Git-based platform. In Ubuntu, this process is fast and easy with a few terminal commands.
Whether you’re contributing to open-source, starting a new feature, or just exploring a codebase, here’s how to use git clone
effectively on Ubuntu.
β
What Does git clone
Do?
The git clone
command copies a remote repository to your local machine. It creates a complete local version of the project, including:
- All the files
- Git history (commits, branches, tags)
- Remote connection for pushing/pulling code
π Prerequisites
Make sure Git is installed on your Ubuntu system.
π₯ Install Git (if not already installed)
sudo apt update
sudo apt install git
Verify installation:
git --version
π£ How to Clone a Git Repository
π Step 1: Copy the Repository URL
Go to the GitHub/GitLab/Bitbucket page of the repository you want to clone.
- Click the green βCodeβ button
- Copy the HTTPS or SSH URL (e.g.
https://github.com/username/repo.git
)
π§² Step 2: Open Terminal and Run git clone
Use this command in the directory where you want to place the project:
git clone https://github.com/username/repo.git
π Example:
git clone https://github.com/octocat/Hello-World.git
Git will:
- Create a new folder named after the repo (e.g.,
Hello-World
) - Download all code and history into that folder
π Optional: Clone into a Custom Folder Name
git clone https://github.com/username/repo.git my-folder
This creates a folder called my-folder
instead of the default repo name.
π Using SSH Instead of HTTPS (Optional)
If you’ve set up SSH keys with GitHub, you can use this format:
git clone gi*@gi****.com:username/repo.git
This avoids typing your username/password for every push/pull.
π§ Post-Clone: Common Follow-Up Commands
After cloning, you can navigate into the project directory and start working:
cd repo-name
Update the repository later with:
git pull origin main # or 'master' or your current branch
β Summary
Task | Command Example |
---|---|
Install Git | sudo apt install git |
Clone a repo | git clone https://github.com/user/repo.git |
Change folder name | git clone https://github.com/user/repo.git myapp |
Use SSH clone | git clone gi*@gi****.com:user/repo.git |
Go into project folder | cd repo |
π Final Thoughts
The git clone
command is a fast and powerful way to begin working with existing projects in Ubuntu. Whether you’re building, learning, or collaborating, cloning is your gateway to Git-powered development.