//tips
//git flowを用いた管理
ブランチ管理に有用なgit flowエクステンションを導入する。
まずインストールから。
brew install git-flow
導入後、git flow initで初期設定を行う。
事前にmaster,developのブランチを作っておくとスムーズ。
私はなぜかnext releaseの方もmasterになってしまいそうだったので、git branch developを作成したら、developをnext releaseとして認識してくれるようになった。
helloという文字列を返す機能を作成する。
git flow feature start echo_hello
Switched to a new branch 'feature/echo_hello'
Summary of actions:
- A new branch 'feature/echo_hello' was created, based on 'develop'
- You are now on branch 'feature/echo_hello'
Now, start committing on your feature. When done, use:
git flow feature finish echo_hello
このコマンドの後にgit branchを押すと
develop
example
* feature/echo_hello
master
test
とfeature/echo_helloにcheckoutして機能の開発に取り込める場所が作られる。
機能の作成方法はシェルスクリプトを使う必要があるようなので下記を参照すると良い。
https://shellscript.sunone.me/tutorial.html
開発を終了した段階で下記コマンドを行う。
git flow feature finish echo_hello
Switched to branch 'develop'
Already up to date.
Deleted branch feature/echo_hello (was 07092a8).
Summary of actions:
- The feature branch 'feature/echo_hello' was merged into 'develop'
- Feature branch 'feature/echo_hello' has been removed
- You are now on branch 'develop'
そうすると自動的にdevelopにマージされる。
今回は特に機能を追加しなくてもマージは成功した。
ちなみにシェルスクリプトも下記に記載する。
echo $SHELLで/bin/bashとでたら
vi ./hello.sh
とし、hello.shスクリプトをviで記述していくことになる。
viのコマンドを記述したら勝手にそちらのエディタが開くのでそちらに、
#!/bin/bash
echo "Hello world!"
を入力し、:wqなどで終了させる。
もしbashではなく、shであったら#!/bin/shとなる。
bash hello.sh
と入力するとHello world!を返す。
https://qiita.com/Lambda34/items/7d24ebe6f7bde5bedddc
//個人用ブランチの利用
Feature-xxxという機能の作成に自分が関わる場合は、
git branch feature-xxx
git checkout feature-xxx
git checkout -b naki/feature-xxx
のような形で自分用のブランチを作成する。
git branch
develop
example
feature-xxx
master
* naki/feature-xxx
test
他にも複数の開発アイデアを持つ場合はブランチをわけ、例えば、ボタンの機能feature-buttonをjsとcssで検討している場合、
git branch -m feature-xxx feature-button
develop
example
feature-button
master
naki/button-css
* naki/button-js
test
このように naki/button-css, naki/button-jsの2つのブランチを作って検証する。
検証で有効な方をfeature-buttonブランチに融合すれば良いので、融合元のブランチに移動し、融合したいものをマージすれば良い。
git checkout feature-button
git merge naki/button-js
この考え方を利用して、コンフリクトを事前検出する方法もある。
下記のケースで、featureで開発を進めたものをdevelopに統合したいとき、developの更新に伴うコンフリクトを想定して、naki/feature-xxxのように開発した機能を個人ブランチにcheckoutし、それを個人ブランチにdevelopを統合する。
git branch
develop
example
feature-xxx
master
* naki/feature-xxx
test
git checkout -b naki/feature-xxx
git merge develop
本来はdevelopにcheckoutをして feature-xxxをマージするが、個人ブランチとのマージによりコンフリクトを事前検証し、問題がないか確認できる。
マージした後も、ブランチは残るので、コンフリクトが解消でき問題ない場合は、developにnaki/feature-xxxをマージすれば良い。すでにコンフリクトの解消は済んでいるのでこのマージで問題は起きない。
手本となるgithubの使用方法はオープンソースプロジェクトから見つけることができ、例えば、googleのリポジトリは
https://github.com/google
から確認できる。
現在は共同開発をしていないので複雑な操作はする必要がないのでgithubの基本的な使い方はこのぐらいにし、chatアプリの制作準備に移る。