Cloning Repositories
Create a local copy of a remote repository with git clone.
What is Clone?
Clone creates:
- A complete copy of the repository
- All branches and history
- Remote tracking (origin)
Basic Clone
Clone Commands
| Command | Description |
|---|---|
git clone <url> | Clone to folder with repo name |
git clone <url> <folder> | Clone to specific folder |
git clone --depth 1 | Shallow clone (latest only) |
git clone --branch <name> | Clone specific branch |
Clone URLs
HTTPS
git clone https://github.com/user/repo.git
SSH
git clone git@github.com:user/repo.git
Clone Options
Specific Branch
git clone -b develop https://github.com/user/repo.git
Shallow Clone
git clone --depth 1 https://github.com/user/repo.git
Only gets the latest commit - faster for large repos.
Specific Folder Name
git clone https://github.com/user/repo.git my-project
After Cloning
The cloned repository:
- Has
originremote set up - Is on the default branch
- Has all remote branches available
View branches:
git branch -a
Cloning vs Forking
| Action | Use Case |
|---|---|
| Clone | Work on repo you have access to |
| Fork | Create your own copy on GitHub |
Working with Cloned Repos
# Clone
git clone https://github.com/user/repo.git
# Navigate into it
cd repo
# Create branch for your work
git checkout -b my-feature
# Make changes, commit, push
git push -u origin my-feature
Exercise: Simulate Clone
Run a clone command (simulated in this environment):

