Git

How to Get Git to Clone Into Current Directory

Developers often work on the Git versioning control system to track and manage development projects. They perform multiple operations on the Git local repository and then push them to the remote repository. For this purpose, it is required to connect the GitHub hosting service with the Git local repository and specify the repository in which they want to perform the cloning operation.

This post will explain:

So, let’s begin!

How to Clone Remote Repo Into Current Directory Using HTTPS URL?

To get Git to clone into the current directory with HTTPS, first, move to the Git root directory and create a new Git local repository. Next, navigate to it and view the content list. Then, print the current directory where the HEAD is pointing. Run the “$ git clone <https-url> .” command and clone it into the Git current directory.

Let’s check out the following implemented instructions for a better understanding!

Step 1: Navigate to Root Directory

At first, move to the Git leading root directory through the “cd” command:

$ cd "C:\Users\nazma\Git"

 

Step 2: Create Local Repository

Run the “mkdir” command to create a new local repository:

$ mkdir dir_test

 

Step 3: Move to Created Repository

Next, navigate to the newly created repository using the “cd” command:

$ cd dir_test

 

Step 4: View Repository Content List

To view the repository content list, run the “ls” command:

$ ls

 

Step 5: Check Current Directory

Execute the “pwd” command to print the directory where HEAD is currently pointing:

$ pwd

 

Step 6: Clone Git Remote Repository Into Current Directory

Finally, execute the “git clone” command with the remote repository HTTPS URL and add the dot “.” at the end of the command to clone it into the current directory:


Step 7: View Repository Content

Lastly, view the content list of the current directory by executing the “ls” command along with the “-1a” option for listing the hidden file:

$ ls -1a

 

How to Clone Remote Repo into Current Directory Using SSH URL?

To clone the Git remote repository into the current directory using SSH URL. Follow the below-provided steps.

Step 1: Create New Local Repository

Run the “mkdir” command and create a new local repository:

$ mkdir dir_test2

 

Step 2: Move to Newly Created Repository

Next, navigate to the newly created repository by executing the “cd” command:

$ cd dir_test2

 

Step 3: Clone Remote Repository Into Current Directory

Run the “git clone” command along with the remote repository SSH URL and add the dot “.” at the end of the command to clone it into the current directory:

$ git clone git@github.com:GitUser0422/Linux_2.git .

 

Step 4: View Content List

Lastly, check the content list of the repository with hidden files and folders by executing the “ls -1a” command:

$ ls -1a

 

That’s it! We have taught you the procedure to get Git to clone into the current directory with HTTPS and SSH URLs.

Conclusion

To get Git to clone into the current directory with HTTPS and SSH URLs, firstly, navigate to the Git root directory and create a new local repository. Then, move to the newly created repository. Check the content list and print the directory where the HEAD is pointing. Execute the “$ git clone” command with the remote repository HTTPS or SSH URLs and dot “.” to clone it into the current directory. Lastly, check the list of content, including hidden files. This post explained the method of cloning the remote repository into the Git current directory.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.