Clone a Repository
Cloning creates a local copy of a remote repository on your machine, including the full commit history.
Basic Usage
git clone https://github.com/username/repository.git
This creates a folder named repository in your current directory.
Clone into a Specific Folder
git clone https://github.com/username/repository.git my-folder
Clone a Specific Branch
git clone -b develop https://github.com/username/repository.git
Clone via SSH
SSH is preferred for regular development since it avoids entering credentials on every push/pull.
git clone git@github.com:username/repository.git
To use SSH cloning, you need to add your public SSH key to your GitHub/GitLab account first.
What Happens After Cloning
After cloning, Git automatically:
- Sets
originas the name for the remote URL - Checks out the default branch (usually
main)
You can verify this with:
git remote -v
origin https://github.com/username/repository.git (fetch)
origin https://github.com/username/repository.git (push)