When would you use git clone over git clone –mirror?
You would use
git clone over
git clone --mirror in different scenarios, depending on your use case and requirements for the cloned repository:
git clone when:
- Regular Development: If you are a developer or contributor who needs a copy of the repository to work on, you should use
git clone. The regular clone creates a working directory with the complete history, branches, and all files. You can make changes, commit them, and push your changes to the remote repository.
- Collaborative Workflow: When collaborating with other team members,
git cloneallows each developer to have their local copy of the repository, making it easy to work independently on different features or bug fixes.
- Standard Repository Backup: If you want to create a backup of the repository, you can use
git cloneto create a full-fledged copy of the repository on another location.
git clone --mirror when:
- Mirroring a Repository: The primary purpose of
git clone --mirroris to create a full mirror or replica of a repository, including all branches, tags, and commit history, without the working directory.
- Centralized Backup: If you want to maintain a centralized backup of the entire repository, including all refs (branches and tags), without the working files,
git clone --mirroris suitable.
- Moving to a New Hosting Service: If you want to migrate a Git repository from one hosting service to another while preserving the full history and refs,
git clone --mirrorcan be used to clone the original repository and then push it to the new hosting service.
- Redistribution or Forking: If you want to create a fork of a repository while preserving the complete history and refs without any intention of contributing back directly,
git clone --mirrorcan be used.
git clone --mirror creates a bare repository, which means it doesn’t have a working directory or allow you to make changes directly. It’s primarily used for repository mirroring, backups, migration, and redistribution scenarios. For regular development and collaboration, using
git clone is the appropriate choice.