Typically we’re cloning a git repository into a dedicated directory. The cloned directory then has the name of the repository which, by default, is the repository’s slug. You may also define the directory name in which the git repository’s contents will be cloned.
Recently we prepared the directory structure on a local computer before cloning the remote repository. When cloning the repository we wanted git to put the contents into the current directory. This tutorial shows you how to do that.
git Series Overview
- 'flow' Is Not a git Command
- Git Prune Remote Branches That No Longer Exist
- Clone Into Current Directory
Clone a Remote git Repository into the Current Directory
The git clone
command allows you to clone a git repository from a remote machine to your local hard drive. The signature of git clone
expects a repository URL as the first argument. You may provide an optional second argument which is the directory name in which to put the contents.
You may also use the dot .
as the target directory for the clone. The dot represents the current directory and git properly resolves it:
# put a dot after the git repository URL to clone into the current directory
git clone git@github.com:user/my-project.git .
That’s it!