How to Clone a Git Repository Content to a Given Folder

When you clone a Git repository with the git clone command like so:

git clone https://github.com/collizo4sky/WP_List_Table-Class-Plugin-Example.git

The content of the repo will be downloaded or cloned into a WP_List_Table-Class-Plugin-Example (repository name) folder.

This might not be your expected behavior. An example of what your expection might be is for the content of the Git repository to be cloned into your current directory or to a named folder in the current directory.

To clone a git repo to your current directory, include . after the repo’s HTTPS or SSH address like so:

git clone https://github.com/collizo4sky/WP_List_Table-Class-Plugin-Example.git .

To clone to a folder called wordpress, use the command below:

git clone https://github.com/collizo4sky/WP_List_Table-Class-Plugin-Example.git wordpress

You can also clone the repo content to a nested folder like so:

git clone https://github.com/collizo4sky/WP_List_Table-Class-Plugin-Example.git wordpress/wp-content/plugins/hello-word

Note: the above commands requires that the folder (where the repository content will be downloaded to) must be empty.

If the folder isn’t empty, your last resort might be to initialize git in the folder, add the repo URL as origin and finally make a pull like so:

git init
git remote add origin https://github.com/collizo4sky/WP_List_Table-Class-Plugin-Example.git
git pull

The above commands can be simplified to a git alias such that running
git cp https://github.com/collizo4sky/WP_List_Table-Class-Plugin-Example.git will perform the same task as the above commands.

To create a cp alias, add the line of code below to your .gitconfig file.

[alias]
	cp = "!git init && git remote add origin $1 && git pull"

If you have git alias already, be sure to remove [alias] from the code above and only add the cp command to your existing alias.

La Fin!

Don’t miss out!
Subscribe to My Newsletter
Invalid email address