HOWTO · Git
空でない Git ディレクトリにクローンを作成する
この記事では、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 コマンドを使用してリポジトリのクローンを作成することはできません。
ディレクトリ内のファイルが不要な場合は削除できますが、両方のリポジトリ内のファイルをマージする場合は、以下の方法を使用してください。
-
リモートリポジトリのクローンを作成するディレクトリを開きます。
cd \Delftscopetech1 -
このコマンドを使用して新しいリポジトリを設定します。
```bash
git init
```
-
リモートリポジトリを追加します
git remote add origin https://github.com/Wachira11ke/Delftscopetech.git -
プルしてマージ
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
空でないディレクトリを使用して、リモートリポジトリをローカルリポジトリに正常に複製しました。