LoginSignup
0
0

More than 1 year has passed since last update.

git clone 〜 リモートリポジトリ追加までの流れ

Last updated at Posted at 2023-03-08

git cloneとは

Github上のリポジトリをローカル環境にクローンすることができる。

基本的な使い方

$ git clone [リポジトリを指定する]

Githubのリポジトリからソースコードをダウンロード

codeの箇所をクリックするとURLが表示されるので、それをコピーする
スクリーンショット 2023-03-08 21.06.21.png
コピーしたURLを使用して、CLIでgit cloneを実行

ソースコードを配置したいディレクトリ
$ git clone コピーしたURL

# ダウンロードしたディレクトリに移動
$ cd sample_app

ディレクトリを指定してクローンする

リポジトリを指定した後にディレクトリ名を入力すると、そのディレクトリが新たに作成され、その配下にクローンの内容が反映されます。

$ git clone [リポジトリを指定する] [ディレクトリ名]

※ディレクトリが元々存在しても、配下にファイルやディレクトリがなければクローンできます。ファイルが一つでもあるとクローンできません。

その他のオプション

-hオプションでオプション一覧を確認できます。

$ git clone -h
usage: git clone [<options>] [--] <repo> [<dir>]

    -v, --verbose         be more verbose
    -q, --quiet           be more quiet
    --progress            force progress reporting
    --reject-shallow      don't clone shallow repository
    -n, --no-checkout     don't create a checkout
    --bare                create a bare repository
    --mirror              create a mirror repository (implies bare)
    -l, --local           to clone from a local repository
    --no-hardlinks        don't use local hardlinks, always copy
    -s, --shared          setup as shared repository
    --recurse-submodules[=<pathspec>]
                          initialize submodules in the clone
    --recursive[=<pathspec>]
                          alias of --recurse-submodules
    -j, --jobs <n>        number of submodules cloned in parallel
    --template <template-directory>
                          directory from which templates will be used
    --reference <repo>    reference repository
    --reference-if-able <repo>
                          reference repository
    --dissociate          use --reference only while cloning
    -o, --origin <name>   use <name> instead of 'origin' to track upstream
    -b, --branch <branch>
                          checkout <branch> instead of the remote's HEAD
    -u, --upload-pack <path>
                          path to git-upload-pack on the remote
    --depth <depth>       create a shallow clone of that depth
    --shallow-since <time>
                          create a shallow clone since a specific time
    --shallow-exclude <revision>
                          deepen history of shallow clone, excluding rev
    --single-branch       clone only one branch, HEAD or --branch
    --no-tags             don't clone any tags, and make later fetches not to follow them
    --shallow-submodules  any cloned submodules will be shallow
    --separate-git-dir <gitdir>
                          separate git dir from working tree
    -c, --config <key=value>
                          set config inside the new repository
    --server-option <server-specific>
                          option to transmit
    -4, --ipv4            use IPv4 addresses only
    -6, --ipv6            use IPv6 addresses only
    --filter <args>       object filtering
    --also-filter-submodules
                          apply partial clone filters to submodules
    --remote-submodules   any cloned submodules will use their remote-tracking branch
    --sparse              initialize sparse-checkout file to include only files at root
    --bundle-uri <uri>    a URI for downloading bundles before fetching from origin remote

リモートリポジトリに追加

まずローカルリポジトリを作成する

$ git init

github上でリモートリポジトリを作成する

スクリーンショット 2023-03-12 11.19.04.png
スクリーンショット 2023-03-12 11.25.29.png

  • publicを選択すると、リポジトリを公開する設定となり誰でも閲覧することができます。
  • privateは自分と、許可したユーザーのみが閲覧できます。

作成したリポジトリに移動
スクリーンショット 2023-03-12 11.30.31.png

リモートリポジトリを登録

$ git remote add <リモート名> <コピーしたリポジトリURL>

$ git remote add origin https://github.com/keroropper/sample.git
  • ローカルリポジトリの内容をリモートリポジトリに反映させる
$ git push origin master

参考サイト

【Git入門】git cloneの使い方!ソースコードをダウンロードしてみよう
これでもう怖くない、Git/GitHubにおけるリモートリポジトリの作成、確認、変更、更新時の基本5コマンド

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0