๐Ÿ“ Git & GitHub

Git Clone: Complete Guide ๐Ÿ“ฆ

P
Author
PyLand Team
๐Ÿ“…
Published
06.05.2026
โฑ๏ธ
Reading time
3 min
๐Ÿ‘๏ธ
Views
386
๐ŸŒฑ
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. File โ†’ Clone Repository
  2. GitHub.com tab
  3. Select the repository
  4. Choose a folder
  5. Clone

Method 2: By URL

  1. File โ†’ Clone 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

๐Ÿ“

Undo and Revert in GitHub Desktop: Fix Mistakes Wโ€ฆ

A commit is not a point of no return. GitHub Desktop lets you rebuild a...

๐Ÿ“… 16.07.2026 ๐Ÿ‘๏ธ 359
๐Ÿ“

History, Diffs, and Web Commits on GitHub

GitHub lets you read repository history, inspect individual commit diffs, view the history of one...

๐Ÿ“… 16.07.2026 ๐Ÿ‘๏ธ 312
๐Ÿ“

Your First Git Commit

Your first commit starts with initializing a repository, configuring the author identity, and selecting the...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 343
๐ŸŽ“ Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

Git & GitHub Desktop: Teamwork Without the Pain Open course curriculum