How do you clone a GitHub repository?
Short answer: on the repository page, click the green Code button and copy the URL. Then open a terminal in the folder where you want the project and run git clone followed by that URL. Git downloads every file and the whole history into a new folder named after the repository.
git clone https://github.com/4GeeksAcademy/html-hello
cd html-helloYou need Git installed. Without the terminal, you can also clone with GitHub Desktop or from VS Code.
git clone downloads the repository, origin already points to GitHub and the project is ready to open.
Every way to clone a repository
| What you want | Command or tool |
|---|---|
| Clone with HTTPS (the usual way) | git clone https://github.com/user/repo |
| Clone with SSH | git clone git@github.com:user/repo.git |
| Clone with the GitHub CLI | gh repo clone user/repo |
| Choose the folder name | git clone https://github.com/user/repo my-folder |
| Clone into the current empty folder | git clone https://github.com/user/repo . |
| Clone one branch | git clone -b develop https://github.com/user/repo |
| Only the latest version, without history | git clone --depth 1 https://github.com/user/repo |
| Include submodules | git clone --recurse-submodules https://github.com/user/repo |
| Without the terminal | GitHub Desktop, or VS Code: Git: Clone |
Clone a repository step by step
1. Copy the URL. Open the repository on GitHub, click Code and copy the URL from the HTTPS tab.
2. Open a terminal in the right folder. Use Terminal on Mac or Linux, or Git Bash or PowerShell on Windows. Move to the folder where you keep your projects:
cd ~/projects3. Run git clone with the URL you copied:
git clone https://github.com/4GeeksAcademy/html-hello
# Cloning into 'html-hello'...
# Resolving deltas: 100% (55/55), done.4. Enter the folder and check it:
cd html-hello
git remote -v
# origin https://github.com/4GeeksAcademy/html-hello (fetch)
# origin https://github.com/4GeeksAcademy/html-hello (push)The remote origin points to GitHub, so git pull brings new changes and git push sends yours, if you have permission. Open the folder in your editor and start working.
