JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Git >

Clone into a non-empty Git directory

Author:JIYIK Last Updated:2025/03/29 Views:

This article will show you how to clone a Git repository to a non-empty folder. This operation comes in handy when you want to merge files from a remote repository with files in your current local repository.


In Git, clone into a non-empty Git directory

It is easy to clone a remote repository. We use the following command.

git clone <repository-url> <directory>

This will clone the remote repository into the specified directory. However, the directory should be empty.

If you try to clone in a non-empty repository, you will get 致命警告a message like the one below.

pc@JOHN MINGW64 ~/Git (main)
$ git clone https://github.com/Wachira11ke/Delftscopetech.git
fatal: destination path 'Delftscopetech' already exists and is not an empty directory.

Since the directory Delftscopetechalready exists and contains some files, we cannot use git clonethe command to clone our repository.

If you don't need the files in the directory you can delete them, but if you want to merge the files in two repositories use the method below.

example:

pc@JOHN MINGW64 ~/Git (main)
$ cd \Delftscopetech1

pc@JOHN MINGW64 ~/Git/Delftscopetech1 (main)
$ git init
Initialized empty Git repository in C:/Users/pc/Git/Delftscopetech1/.git/

pc@JOHN MINGW64 ~/Git/Delftscopetech1 (master)
$ git remote add origin https://github.com/Wachira11ke/Delftscopetech.git

pc@JOHN MINGW64 ~/Git/Delftscopetech1 (master)
$ git pull origin master --allow-unrelated-histories
fatal: couldn't find remote ref master

pc@JOHN MINGW64 ~/Git/Delftscopetech1 (master)
$ git pull origin main --allow-unrelated-histories
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 610 bytes | 3.00 KiB/s, done.
From https://github.com/Wachira11ke/Delftscopetech
 * branch            main       -> FETCH_HEAD
 * [new branch]      main       -> origin/main

We have successfully cloned our remote repository into our local repository with a non-empty directory.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Fatal: Refusing to Merge Unrelated Histories error in Git

Publish Date:2025/03/29 Views:123 Category:Git

This article outlines the steps required to resolve the fatal: refusing to merge unrelated histories error in Git. We usually encounter such errors when trying to merge two unrelated Git projects into one branch. It pops up when the receivi

Clone all branches in Git

Publish Date:2025/03/29 Views:132 Category:Git

When developing software using Git, you can create different branches for different features. This article will explain how to clone all different branches from remote to local in Git. Git clone all branches When using Git, you may need to

Clone a private repository in Git

Publish Date:2025/03/29 Views:106 Category:Git

This article will teach you how to use Git to clone a private repository hosted on Github. Git is a version control system used to track changes in a project directory. Git uses commits for such purposes. Github provides Internet hosting fo

Force pull overwrite in Git

Publish Date:2025/03/29 Views:119 Category:Git

Git is the most popular and demanded version control system today. The user interface of Git is similar to other version control systems. We can log in, clone the repository and make commits. However, Git has some significant differences th

Git authentication

Publish Date:2025/03/28 Views:163 Category:Git

This article demonstrates connecting a local repository to a remote repository on GitHub/Gitlab without getting 身份验证失败 error messages. Creating a local repository from scratch in Git To create a local repository from scratch, fo

Log graphs in Git

Publish Date:2025/03/28 Views:96 Category:Git

This article shows you how to use git log the command to graphically view the commit history in Git. Viewing log graphs in Git The command git log displays all the repository history at once snapshots(commits) . This command has a default f

Git refresh remote branch

Publish Date:2025/03/28 Views:94 Category:Git

Git is considered to be the most accurate and the most used software by developers in their projects and can be operated by multiple developers simultaneously. It provides many unique and quirky features to the developers which are very dif

Updating Git on Mac

Publish Date:2025/03/28 Views:182 Category:Git

When working on Git, you should stay updated with the latest version to get its latest features. This article will discuss how to install and update the latest version of Homebrew and Git on your personal computer. Homebrew on Mac Homebrew

Enable Git Tab Auto-Complete

Publish Date:2025/03/28 Views:110 Category:Git

This tutorial demonstrates how to enable git tab autocompletion. Importance of enabling Git Tab auto-completion When developers work with source code, they mostly prefer Git as it is a very familiar and convenient platform for developers th

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial