Git & GitHub
/Beginner
git clone
Definition
A command that creates a local copy of a specific remote repository (usually from GitHub, GitLab, etc.).
Explain Like I'm New
The Download button on steroids. Instead of downloading a ZIP file of the code, `git clone` downloads the code AND the entire history of every change ever made to it, while also setting up a connection to the original internet server.
Real World Example
You get hired at a new company. On day 1, they give you a link to the company's codebase on GitHub. You run `git clone <link>` to download the project to your work laptop so you can start working.
Common Use Cases
- •Contributing to Open Source
- •Onboarding to new projects
Crucial Command Flags
| Flag / Option | Description |
|---|---|
| --depth 1 | Shallow clone. Only clone the very last commit (saves time/space). |
| --branch [name] | Clone only a specific branch instead of the default. |
| --bare | Make a bare Git repository (no working directory). |
Terminal Output
bash / terminal
# Clone a repository from GitHub
$ git clone https://github.com/facebook/react.git
# This creates a folder named 'react' in your current directory.
# Navigate into it:
$ cd react
# You now have the entire React source code and history on your machine!
# You can also clone it and give the folder a custom name:
$ git clone https://github.com/facebook/react.git my-react-folder
Interview Questions
basic
- Do you need to run `git init` after running `git clone`?
intermediate
- What is the default name given to the remote server connection when you clone a repository?