Gitの動作を理解するために、Gitのコマンドを実際に試して、結果を見てみました。
1つの記事内で一連のGitコマンドが完結しているので、これら一連のコマンドを順に実行させて結果を見ることで、一連のGitの動作を実際に体感でき、一通り独習することが可能です。
※前回記事のリポジトリ状態からの続きになっています。
前回記事へ | 目次へ:Git関連記事のまとめページ | 次回記事へ |
---|
実行例
(※試行用にlocal-repo3を作成)
cd /test-space
mkdir local-repo3
cd /test-space/local-repo3
git init
git remote add origin "D:/test-space/remote-repo1.git"
git log
↓
結果:
fatal: your current branch 'master' does not have any commits yet
-----
(※リモートリポジトリからmasterブランチのみを取得して環境準備)
git fetch origin master
git log --oneline --graph --all
↓
結果:
* 1247fa9 (origin/master) message R4
* fab68d8 message R3
* c69a305 message R1
* 94996a0 message4
* 20bbab7 message3
* 00cad71 message2
* 4ace194 message1
-----
(※--bareでリモートリポジトリを作成せず、2個のローカルリポジトリの間でも同様にやり取り可能)
※ローカルリポジトリ(非ベアリポジトリ)へのアクセスを追加登録
git remote add origin-L2 "D:/test-space/local-repo2"
git remote -v
↓
結果:
origin D:/test-space/remote-repo1.git (fetch)
origin D:/test-space/remote-repo1.git (push)
origin-L2 D:/test-space/local-repo2 (fetch)
origin-L2 D:/test-space/local-repo2 (push)
※ローカルリポジトリからmasterブランチの履歴情報を取得
git fetch origin-L2 master
↓
結果:
From D:/test-space/local-repo2
* branch master -> FETCH_HEAD
* [new branch] master -> origin-L2/master
git log --oneline --graph --all
↓
結果:
* 1247fa9 (origin/master) message R4
* fab68d8 message R3
* c69a305 (origin-L2/master) message R1
* 94996a0 message4
* 20bbab7 message3
* 00cad71 message2
* 4ace194 message1
(※origin/masterの他に、同じ履歴の系列にorigin-L2/masterが追加される)
環境
Windows 10、PortableGit-2.40.0-64-bitを使用、全てローカルPC上で実施、GitHub等は不使用。