ファイルのバージョン(リビジョン)を管理してくる仕組みの1つ。
他にはsubversionとかがある。
github や bitbucket は git にソーシャルな仕組みを付け加えたサービス名を指す。
バージョン管理したいフォルダ(リポジトリ)がローカルPCとクラウドの両方にある感じ。
それらをうまいこと同期させたり枝分けさせたりできる感じ。
例)
- AさんとBさんのローカルに同じファイルがある状態
- Aさんがローカルでファイルを修正
- Bさんがローカルで別のファイルを修正
- Aさんが修正をクラウド(リモート)に送信(push)
- Bさんがリモートのファイルを受信(pull)
- Bさんのローカルでは自分の修正しているものにAさんの修正が加わった状態
正直パっとはわかりにくいけど、
誰がどこを修正しても push / pull の動きだけで常に同期できる。
win: コマンドプロンプト起動してgit --version
を叩いてみる
mac: ターミナル起動してgit --version
を叩いてみる
C:\Users\a_shimada> git --version
git version 1.9.5.msysgit.0
こんな感じの結果が返ってくればインストールさてれいる
インストールされてなかったら以下からインストール
winならtortoisegit(とーたすぎっと)を入れると割りとGUIで操作できるっぽい
https://code.google.com/p/tortoisegit/wiki/Download
多分GUIあるけど、詳しくないのと
細かい操作は出来なそうなのでコマンドでの操作方法をつらつら書く。
-
リモートリポジトリの作成 bitbucketとかで非公開の新規リポジトリ作成
リポジトリURL:https://bitbucket.org/[username]/[リポジトリ名].git -
ローカルにバージョン管理させるフォルダ・ファイルを作る
コマンドプロンプト / ターミナル でそのディレクトリまでいく
[shimada🐱 shimada-no-MacBook-Air]
>>> [workspace2] $ mkdir gittest
[shimada🐱 shimada-no-MacBook-Air]
>>> [workspace2] $ cd gittest/
[shimada🐱 shimada-no-MacBook-Air]
>>> [gittest] $ vim test.html
[shimada🐱 shimada-no-MacBook-Air]
>>> [gittest] $ ll
total 8
drwxr-xr-x 3 shimada staff 102 8 11 20:48 ./
drwxr-xr-x 10 shimada staff 340 8 11 20:47 ../
-rw-r--r-- 1 shimada staff 48 8 11 20:48 test.html
- このディレクトリをgitで管理するよ宣言(git init)
[shimada🐱 shimada-no-MacBook-Air]
>>> [gittest] $ git init
Initialized empty Git repository in /Users/shimada/Documents/workspace2/gittest/.git/
- まだローカルにしかファイルがないので、リモートをどこにするか設定
[shimada🐱 shimada-no-MacBook-Air]
>>> [gittest] $ git remote add origin https://bitbucket.org/hakopako/test.git
- ローカルとリモートの差分修正をコミット(編集確定)
[shimada🐱 shimada-no-MacBook-Air]
>>> [gittest] $ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.html
nothing added to commit but untracked files present (use "git add" to track)
[shimada🐱 shimada-no-MacBook-Air]
>>> [gittest] $ git add .
[shimada🐱 shimada-no-MacBook-Air]
>>> [gittest] $ git commit -m "first commit."
[master (root-commit) caf69ec] first commit.
1 file changed, 6 insertions(+)
create mode 100644 test.html
- ローカルの修正をリモートにpush
[shimada🐱 shimada-no-MacBook-Air]
>>> [gittest] $ git push origin master
Password for 'https://hakopako@bitbucket.org':
Counting objects: 3, done.
Writing objects: 100% (3/3), 246 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://hakopako@bitbucket.org/hakopako/test.git
* [new branch] master -> master
これでリモートと同期完了