비어 있지 않은 Git 디렉토리로 복제

John Wachira 2022년8월23일
비어 있지 않은 Git 디렉토리로 복제

이 기사에서는 Git 저장소를 비어 있지 않은 폴더에 복제하는 방법을 설명합니다. 이 작업은 원격 저장소의 파일을 현재 로컬 저장소의 파일과 병합하려는 경우에 유용합니다.

Git에서 비어 있지 않은 Git 디렉토리로 복제

원격 저장소를 복제하는 것은 쉽습니다. 우리는 아래 명령을 사용합니다.

git clone <repository-url> <directory>

이렇게 하면 원격 저장소가 지정된 디렉토리에 복제됩니다. 그러나 디렉토리는 비어 있어야 합니다.

아래와 같이 비어 있지 않은 저장소에서 복제를 시도하면 치명적인 경고 메시지가 표시됩니다.

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.

Delftscopetech 디렉토리가 이미 존재하고 일부 파일이 포함되어 있으므로 git clone 명령을 사용하여 저장소를 복제할 수 없습니다.

디렉터리에 있는 파일이 필요하지 않다면 삭제할 수 있지만 두 저장소에 있는 파일을 병합하려면 아래 방법을 사용하세요.

  1. 원격 리포지토리를 복제할 디렉터리를 엽니다.

    cd \Delftscopetech1
    
  2. 이 명령으로 새 저장소를 설정합니다.

    git init
    
  3. 원격 저장소 추가

    git remote add origin https://github.com/Wachira11ke/Delftscopetech.git
    
  4. 당겨서 병합

    git pull origin main --allow-unrelated-histories
    

예시:

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

비어 있지 않은 디렉토리가 있는 로컬 리포지토리에 원격 리포지토리를 성공적으로 복제했습니다.

작가: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

관련 문장 - Git Clone