gitの使い方がわからなかったので自分なりに勉強し、まとめてみました。

  • Gitとは?
  • とりあえず雰囲気をつかむ
  • Source Treeを使ってみる
  • 変更をコミットする

目次

  1. Gitとは?
  2. とりあえず雰囲気をつかむ為に
  3. Source Treeを使ってみる
  4. 変更をコミットする

Gitとは?

まず、使い方の前に概念すら知りませんでした。

まずはそこから。。。

Git ≠ GitHub

GitとGitHubは別のものです。

・Gitはバージョンを管理してくれるツール

・GitHubは**「Git」の「ハブ:拠点・中心・集まり」![](https://web.archive.org/web/20200925221612im_/https://i1.wp.com/sho- kun.com/wp- content/uploads/2019/04/図面2.jpg?resize=971%2C743&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i1.wp.com/sho- kun.com/wp-content/uploads/2019/04/図面2.jpg?resize=971%2C743&ssl=1)**

Git = 分散型のバージョン管理をしてくれる

・バージョン管理システムには分散型と集中型がある

┣集中型:リポジトリというサーバーが必要で、そのリポジトリを編集するようなイメージ

┗分散型:サーバーからリポジトリをローカルに持ってきて、ローカルで編集し、リポジトリにアップロードするイメージ

・分散型は常時サーバーに接続する必要がない

僕の認識ではこんな感じです。

とりあえず雰囲気をつかむ為に

こういうものはとりあえず触ってみないとわからない!!!

しかし、Git自体は「CUIツール」で、コマンドラインから操作するツール

とりあえず雰囲気をつかみたかったので今回は「Source Tree」を使用しました

Source Treeとは、GitをGUIで操作できるツールです。

![](https://web.archive.org/web/20200925221612im_/https://i1.wp.com/sho- kun.com/wp- content/uploads/2019/04/キャプチャ.png?resize=1203%2C789&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i1.wp.com/sho- kun.com/wp-content/uploads/2019/04/キャプチャ.png?resize=1203%2C789&ssl=1)

このような感じで画面でポチポチするだけでGitが使えます。

インストール等は省略します。

Source Treeを使ってみる

とりあえずローカルリポジトリ(Gitで管理できるローカルのデータ置き場)を作ってみます。

Source Treeを開いて「Local」→「Create」![](https://web.archive.org/web/20200925221612im_/https://i1.wp.com/sho- kun.com/wp- content/uploads/2019/04/キャプチャ-1.png?resize=1204%2C789&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i1.wp.com/sho- kun.com/wp-content/uploads/2019/04/キャプチャ-1.png?resize=1204%2C789&ssl=1)

リポジトリにしたいファイル

リポジトリ名

を入力して作成をクリック

![](https://web.archive.org/web/20200925221612im_/https://i2.wp.com/sho- kun.com/wp- content/uploads/2019/04/キャプチャ-2.png?resize=1204%2C789&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i2.wp.com/sho- kun.com/wp-content/uploads/2019/04/キャプチャ-2.png?resize=1204%2C789&ssl=1)

「test」というリポジトリが生成されました!

![](https://web.archive.org/web/20200925221612im_/https://i2.wp.com/sho- kun.com/wp- content/uploads/2019/04/キャプチャ-3.png?resize=1204%2C789&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i2.wp.com/sho- kun.com/wp-content/uploads/2019/04/キャプチャ-3.png?resize=1204%2C789&ssl=1)

エクスプローラーから今回作成したリポジトリを開き「index.php」を作ります

<?php
 echo "test page";
?>

その後Source Treeに戻るとこのような画面が表示されます。

![](https://web.archive.org/web/20200925221612im_/https://i0.wp.com/sho- kun.com/wp- content/uploads/2019/04/キャプチャ-4.png?resize=1204%2C789&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i0.wp.com/sho- kun.com/wp-content/uploads/2019/04/キャプチャ-4.png?resize=1204%2C789&ssl=1)

変更や追加したファイルをGitに登録するには

1.インデックスにステージ

2.リポジトリにコミット

する必要があります。

選択したファイルをリポジトリに追加しています。

まず「index.php」をステージします

「index.php」を選択して「選択をインデックスに追加」をクリック

![](https://web.archive.org/web/20200925221612im_/https://i0.wp.com/sho- kun.com/wp- content/uploads/2019/04/キャプチャ-5.png?resize=1204%2C789&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i0.wp.com/sho- kun.com/wp-content/uploads/2019/04/キャプチャ-5.png?resize=1204%2C789&ssl=1)

すると「indexにステージしたファイル」に「index.php」が移動します。

今回追加する内容がどのようなものなのか、コメントをつけることができます。

コメントは「新たにindex.phpを追加しました」でいいでしょう。

コミットをクリック

![](https://web.archive.org/web/20200925221612im_/https://i2.wp.com/sho- kun.com/wp- content/uploads/2019/04/キャプチャ-7.png?resize=1204%2C789&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i2.wp.com/sho- kun.com/wp-content/uploads/2019/04/キャプチャ-7.png?resize=1204%2C789&ssl=1)

すると左の「ブランチ」の下に「master」が生成されます

![](https://web.archive.org/web/20200925221612im_/https://i1.wp.com/sho- kun.com/wp- content/uploads/2019/04/キャプチャ-8.png?resize=1204%2C789&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i1.wp.com/sho- kun.com/wp-content/uploads/2019/04/キャプチャ-8.png?resize=1204%2C789&ssl=1)

これでリポジトリに、新たに追加した「index.php」をコミットすることができました。

![](https://web.archive.org/web/20200925221612im_/https://i2.wp.com/sho- kun.com/wp- content/uploads/2019/04/キャプチャ-9.png?resize=1204%2C789&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i2.wp.com/sho- kun.com/wp-content/uploads/2019/04/キャプチャ-9.png?resize=1204%2C789&ssl=1)

変更をコミットする

エクスプローラーからリポジトリを開き、「index.php」を以下のように編集します

<?php
 echo "test page";
 phpinfo();
?>

そしてSource Treeを開くと「コミットされていない変更があります」と表示されます。

全てインデックスに追加をクリックして

コミットをクリック

![](https://web.archive.org/web/20200925221612im_/https://i0.wp.com/sho- kun.com/wp- content/uploads/2019/04/キャプチャ-11.png?resize=1204%2C789&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i0.wp.com/sho- kun.com/wp-content/uploads/2019/04/キャプチャ-11.png?resize=1204%2C789&ssl=1)

先ほどと同じようにコメントを入れてコミットします。

![](https://web.archive.org/web/20200925221612im_/https://i1.wp.com/sho- kun.com/wp- content/uploads/2019/04/キャプチャ-12.png?resize=1204%2C789&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i1.wp.com/sho- kun.com/wp-content/uploads/2019/04/キャプチャ-12.png?resize=1204%2C789&ssl=1)

すると「ブランチ」→「master」が更新されます。

![](https://web.archive.org/web/20200925221612im_/https://i0.wp.com/sho- kun.com/wp- content/uploads/2019/04/キャプチャ-13.png?resize=1204%2C789&ssl=1)![](https://web.archive.org/web/20200925221612im_/https://i0.wp.com/sho- kun.com/wp-content/uploads/2019/04/キャプチャ-13.png?resize=1204%2C789&ssl=1)

変更した箇所が

+ phpinfo();

このように表記されています。

とりあえずこれで変更したファイルをリポジトリにコミットすることができました