0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gitについて勉強する。第四弾 (リモートリポジトリとやり取りするコマンド 編)

Last updated at Posted at 2019-10-03

git remote

リモートリポジトリの設定内容が表示されます。
そのままだと、リモートリポジトリ名しか表示されないので、
URLなどの情報を見る場合、以下のオプションを付けます。

  • git remote -v

git remote add "リモート名" "リモートのURL"

リモートリポジトリを作成できます。
複数のリモートリポジトリを作成することもできます。

git fetch "リモート名"/

リモートリポジトリからローカルリポジトリに情報を取得します。

その後 「git merge "リモート名"/"ブランチ名"」でワーキングディレクトリに反映する事ができます。

git pull "リモート名" "ブランチ名"

リモートリポジトリから、ローカルリポジトリに情報を反映し、ワーキングディレクトリに反映させることをセットで行うことができます。

フェッチだとこうですが

  • git fetch origin
  • git merge origin/master

下記コマンドで上記2つと同じことをしています。

  • git pull origin master
    ちなみにorigin masterの場合、省略して「git pull」でも良いです。

pullの注意点

git pullのほうが簡単だし、fetchの存在理由ある?
となりますが、pullには一つ落とし穴があります。

「git pull origin hoge」と仮に実行した場合、 git pullの挙動は

  1. リモートのorigin/hogeの情報をローカルのorigin/hogeに取得する。
  2. 「今現在いるブランチ」にhogeを統合する。
    となります。

つまり、自分がorigin/masterにいる場合、hogeの内容がmasterに統合されてしまうことになります。

git remote show "リポジトリ名"

リモートの状態の詳細を表示する事ができます。
例:git remote show origin

git remote rename "旧リモート名" "新リモート名"

リモート名の変更ができます。

git remote rm "リモート名"

リモート名の変更ができます。

次・第五弾

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?