Clone
You might say
Here's a project URL. How do I download the whole codebase to my computer so I can edit it?
Create a local copy of a remote repository and its historyClone downloads a repository, creates a working directory, and configures the original location as a remote. It is normally the first step when joining an existing project. Check the destination path and repository source before running it.
When to use it
- Start work on an existing repository<> Code ▾https://github.com/oil-oil/my-first-page.git📋Use the green Code button to copy the HTTPS address
- Download a full project history$ git log --onelinee7b2d48 Fix button misalignment on mobilea3f9c21 Finish the home-page navigation0f1e2d3 Initialize project
- Create a fresh local working copyFirst clone of the full repository→Then pull incremental updates
- Set up the default remote automatically⑂ Fork→Create a repository copy under your accountFork copies on the hosting platform; clone downloads locally
When NOT to use it
- Clone into a directory that already contains important filesDownload ZIP→git log cannot runA ZIP includes working files, not the .git directory or commit history
- Download code from an untrusted source and run it immediately$ git pushremote: Permission to oil-oil/my-first-page.git denied.
- Clone again every time the remote changes📁 my-first-page
📁 my-first-page-2
📁 my-first-page-latestAfter three clones, it is hard to tell which folder is current - Assume private dependencies and environment settings are included$ npm run devError: Cannot find module 'react'
Anatomy
https://github.com/maya-lee/my-first-page.git
An HTTPS URL works without setting up an SSH key first.
The Git hosting service, such as GitHub or Gitee
The repository owner; after a fork, this segment becomes your account name
The repository name, which also becomes the local folder name by default
Variants
git clone
git clone https://github.com/maya-lee/my-first-page.git
Download working files, repository metadata, and reachable commit history
clone + 名字
git clone <address> my-app
Want to change the name of the local folder
Download ZIP
Code ▾ → Download ZIP
When you only need working files and no Git history
Fork
Upper right of the webpage ⑂ Fork
When you need to create a remote copy under your own account
Typical use cases
Join a project
Set up a new computer
$ git clone https://github.com/maya-lee/my-first-page.git
Cloning into 'my-first-page'...
remote: Enumerating objects: 36, done.
remote: Counting objects: 100% (36/36), done.
Receiving objects: 100% (36/36), 12.4 KiB | 2.1 MiB/s, done.
Created a local repository at ~/projects/my-first-page
Review an open-source repository
$ git log --oneline
e7b2d48 Fix button alignment on mobile
a3f9c21 Finish the home-page navigation
b4c5d67 Home page basic version
0f1e2d3 Initialize project
After cloning, use git log to view the commit history
Create a clean working copy
Further reading
