📝 Git & GitHub

Git Clone: Complete Guide 📦

P
Author
Pyland
📅
Published
06.05.2026
⏱️
Reading time
3 min
👁️
Views
148
🌱
Level
Beginner

git clone is the command for copying (cloning) a remote repository to your computer.

What Is Cloning?

Cloning creates a full copy of a repository:

  • ✅ All files
  • ✅ Full commit history
  • ✅ All branches
  • ✅ All tags

Basic Usage

Syntax

git clone <URL> [folder]

Usage Examples

Basic usage

git clone https://github.com/username/repo.git

Creates a repo/ folder with the contents.

Clone into a specific folder

git clone https://github.com/username/repo.git my-folder

Creates my-folder/ instead of repo/.

Clone a specific branch

git clone -b develop https://github.com/username/repo.git

Clones the develop branch instead of main.

URL Types

git clone https://github.com/username/repo.git

Pros:
- ✅ Easy to set up
- ✅ Works everywhere
- ✅ Works through firewalls/proxies

Cons:
- ❌ Need to enter a password/token on push

SSH (for advanced users)

git clone git@github.com:username/repo.git

Pros:
- ✅ No password on push (uses SSH keys)
- ✅ More secure

Cons:
- ❌ Requires SSH key setup

GitHub CLI

gh repo clone username/repo

If GitHub CLI is installed.

Cloning via GitHub Desktop

Method 1: From your repository list

  1. FileClone Repository
  2. GitHub.com tab
  3. Select the repository
  4. Choose a folder
  5. Clone

Method 2: By URL

  1. FileClone Repository
  2. URL tab
  3. Paste the repository URL
  4. Choose a folder
  5. Clone

Method 3: From the GitHub website

  1. On the repository page click Code
  2. Open with GitHub Desktop
  3. Confirm in the dialog

What Happens During Cloning?

git clone https://github.com/username/repo.git

Git performs:

  1. Creates the repo/ folder
  2. Initializes Git (.git folder)
  3. Adds the origin remote (link to GitHub)
  4. Downloads all objects (commits, trees, blobs)
  5. Checks out the main branch (usually main)

Result:

repo/
├── .git/          # Git database
├── README.md
├── src/
└── ...

Useful Options

Shallow clone

Download only the latest commit:

git clone --depth 1 https://github.com/username/repo.git

Why:
- Faster (less data)
- Saves space
- Full history not needed

When to use:
- CI/CD pipelines
- Temporary use
- Very large repositories

Clone without checkout

git clone --no-checkout https://github.com/username/repo.git

Downloads the data but doesn’t create working files.

Clone with submodules

git clone --recursive https://github.com/username/repo.git

If the project uses Git submodules.

Common Issues and Next Steps

“fatal: could not read Username”

Cause: Repository is private or the URL is wrong.

Fix:
1. Check the URL
2. Make sure you’re logged in to GitHub
3. For private repos — use HTTPS with a token or SSH

“fatal: destination path ‘repo’ already exists”

Cause: The folder already exists.

Fix:
1. Delete the folder: rm -rf repo/
2. Or clone into another folder: git clone ... other-folder

Very slow cloning

Cause: Large repository or slow internet.

Fix:
1. Use --depth 1 (shallow clone)
2. Check your internet speed
3. Try again later (GitHub servers may be under load)

“Permission denied (publickey)”

Cause: SSH key is not configured.

Fix:
1. Use HTTPS instead of SSH
2. Or set up SSH keys: https://docs.github.com/en/authentication/connecting-to-github-with-ssh

After Cloning

Check the remote

cd repo
git remote -v

Output:

origin  https://github.com/username/repo.git (fetch)
origin  https://github.com/username/repo.git (push)

View branches

git branch -a

Switch to another branch

git checkout develop

Update the code

git pull

Fork vs Clone

Clone

A copy of the repository for reading/working.

git clone https://github.com/someone/repo.git

You cannot push to the original.

Fork

A copy of the repository for your own changes.

  1. Click Fork on GitHub
  2. Clone YOUR fork:
    bash git clone https://github.com/YOUR-username/repo.git

You can push to your fork!

Best Practices

✅ Clone into an organized directory structure:

~/Projects/
├── personal/
├── work/
└── learning/

✅ Use HTTPS to start (simpler)

✅ After cloning:
1. Read README.md
2. Install dependencies
3. Create your own branch for work

✅ For large repositories use --depth 1

Now you’re a git clone master! Clone and learn from others’ code! 📦

Your reaction to the article

💬 Comments (0)

🔐 Sign in to leave a comment
🚪 Login
💭

No comments yet

Be the first to share your opinion about this article!

🔗 Similar

Similar articles

Continue learning with these materials

📝

AI Agents: ReAct Loop and Autonomous Actions

A chatbot answers questions. An agent takes action: it calls tools, retrieves real data, and...

📅 30.06.2026 👁️ 111
📝

RAG: Chatting with Documents via Vector Search

RAG (Retrieval-Augmented Generation) is a pattern for working with your own documents. Instead of fine-tuning...

📅 30.06.2026 👁️ 108
📝

Pod: The Smallest Unit in Kubernetes

In Docker you run a container. In Kubernetes the smallest unit is a Pod. It...

📅 30.06.2026 👁️ 101

Did you like the article?

Subscribe to our updates and receive new articles first. Grow with PyLand!