git clone specific folder

How to Clone Git Repository to Specific Folder

By default, git clones a remote repository to your present working directory by creating a new folder in it. Often developers simply clone repository to their present working directory and move it to wherever they want. Sometimes this may not be desirable if the repository is huge. In such cases, it is advisable to directly clone git repo to the required folder instead of cloning it and then copying/moving it. In this article, we will learn how to clone git repository to specific folder.


How to Clone Git Repository to Specific Folder

It is very easy to clone git repository to specific folder. But many beginner developers don’t know about it. Most remote git repository sites like GitHub and BitBucket provide the command to clone git repository to present working directory.

$ git clone repo_url

Instead, if you want to clone git repository to specific folder, just mention it in the above command, after the repo_url

$ git clone repo_url /path/to/folder

Please mention full path to folder above. If you mention relative path, then git command will look for the folder relative to your present working directory.

Here is a simple example to clone remote repository to specific directory.

$ git clone https://github.com/fedingo/helloworld.git  /home/ubuntu/dev-project 

In the above command, we have mentioned the repo URL after git clone command, followed by the specific folder where we want it to be downloaded and initialized. You can replace repo URL and folder location as per your requirement.

That’s it. In this short article, we have learnt how to clone git repository to a specific location on your system. This is much more convenient compared to cloning to your current folder and copying/moving it later. It is a simple modification of default git clone command, that is very useful, especially for beginners.

Also read:

How to Switch Python Version in Ubuntu/Debian
How to Disable HTTP Methods in Apache Server
MySQL Datetime vs Timestamp
How to Remove Line from File Using Python
How to Combine Multiple CSV Files in Python

Leave a Reply

Your email address will not be published. Required fields are marked *