This article will teach the procedure to clone a remote repository to a non-empty directory.
How to Clone Into a Non-Empty Git Directory?
Cloning the remote repository into the non-empty folder becomes crucial when you want to merge the files with the newly cloned remote repository.
Let’s look at the instructions to understand the procedure of cloning into a non-empty Git directory.
Step 1: Open Git Bash
Search for “Git Bash” on your system using the “Startup” menu and launch it:
Step 2: Move to Directory
Move to the directory where you want to clone the remote repository:
In our case, we want to clone the remote repository in “Linux_1” folder:
Step 3: Initialize Empty Repository
Execute the below-provided command to set up an empty repository in the current folder:
Step 4: Copy Remote Repository URL
Next, open the Git remote repository which you want to clone and copy its URL:
Note: If you execute the “$ git clone” command with copied URL, a fatal warning message will display on the command line, which indicates that our destination Git directory is not empty:
You can handle the above-given error by adding a remote repository first and then moving toward cloning.
Step 4: Add Remote Repository
Now, add the remote repository into your specified non-empty Git directory with the “git remote add” command and specify the remote repository URL:
Step 5: Pull and Merge
Lastly, pull and merge the existing data Git directory with the remote repository:
As a result, the remote repository will be successfully cloned into the specified non-empty directory:
We have provided the method of cloning the remote repository into the non-empty Git directory.
Conclusion
To clone the remote repo into a non-empty Git directory, first, move to the specific directory in which you want to clone the repo, and set it up by executing the “$ git init” command. Then, go to the remote Git repo and copy its URL. Execute the “$ git remote add origin” command with copied URL. After that, run the “$ git pull origin master –allow-unrelated-histories” command to merge the local files with remote repository files. In this blog, we have illustrated the procedure of cloning the remote repository into the non-empty Git directory.