gitコマンドの使い方 ~ git remote ~

git remote コマンド概要

リモート追跡ブランチのリモートリポジトリの設定と確認を行うコマンド

基本となる4つの操作を覚えておく。

  • 設定状態の確認
  • 設定の追加
  • 設定の変更
  • 設定の削除

git remote コマンドの使い方

設定の確認

git remote [オプション]

リモート追跡ブランチのリモートリポジトリに設定されているエイリアスの名前を表示する

$ git remote
origin

-vオプションを指定するとリモート追跡ブランチのリモートリポジトリに設定されているエイリアスの名前と  リモートリポジトリのパスを表示する

$ git remote -v
origin  https://github.com/xxx/xxx.git (fetch)
origin  https://github.com/xxx/xxx.git (push)

設定の追加

git remote add [alias-name] [remote-repository]

リモート追跡ブランチのリモートリポジトリに追加設定する

$ git remote add origin https://github.com/xxx/xxx.git

$ git remote -v
origin  https://github.com/xxx/xxx.git (fetch)
origin  https://github.com/xxx/xxx.git (push)

設定の変更

git remote rename [old-alias-name] [new-alias-name]

設定済みのリモート追跡ブランチのリモートリポジトリのエイリアス名を変更する

$ git remote rename origin remo-repo

$ git remote -v
remo-repo       https://github.com/xxx/xxx.git (fetch)
remo-repo       https://github.com/xxx/xxx.git (push)

設定の削除

git remote remove [alias-name]

設定済みのリモート追跡ブランチのリモートリポジトリを削除する

git remote remove remo-repo

git remote -v

git remote の全てのオプションを確認する方法

以下のコマンドを実行するとブラウザでgit remoteのヘルプページが表示される

git remote --help

Gitコマンドの使い方一覧

Git設定git config ~Gitリポジトリの設定~
初期化git init ~ローカルリポジトリの構築~
ログ&設定値確認git log ~commitログの履歴確認~
git status ~作業ディレクトリとステージングエリアの更新状態確認~
git diff ~commitやファイルの差分確認~
git show ~commitの内容確認~
git remote ~リモート追跡ブランチのリモートリポジトリの設定確認~
git reflog ~HEADやブランチの移動履歴の確認と整理~
ステージングエリアの操作git add ~ステージングエリア(インデックス)にファイル追加~
git ls-files ~ステージングエリア(インデックス)のファイル一覧表示~
git rm ~ステージングエリア(インデックス)のファイル削除~
ローカルリポジトリの操作git commit ~blobやtreeなどをまとめたcommitを作成~
git merge ~指定したブランチの内容を取り込み新しいcommitを作成~
git rebase ~commitの履歴の整理~
git cherry-pic ~特定のcommitの変更内容だけを取り込む~
git cat-file ~リポジトリのオブジェクト(commit,tree,blob)の内容表示~
git revert ~指定したcommitを取り消すcommitを作成~
commitのエイリアスなどgit branch ~commitツリーの枝(ブランチ)を作成~
git tag ~リリースなどのタイミングで特定のcommitに名前を付ける~
git stash ~commitを作成する前の変更内容を一時保存~
commitの内容をステージングエリアや作業ディレクトリに反映git checkout ~commitをステージングエリアと作業ディレクトリに展開~
git reset ~HEADの位置やステージングエリアと作業ディレクトリの内容を変更~
リモートリポジトリとのやり取りgit clone ~リモートリポジトリからローカルリポジトリ作成~
git fetch ~リモートリポジトリのブランチをローカルリポジトリに反映~
git pull ~git fetchとgit mergeを同時に行う~
git push ~ローカルリポジトリのブランチをリモートリポジトリに反映~