github関連(2019/02/16)

# github関連(2019/02/16)

* もともとあったプロジェクトはリモートと紐付いていた。 →`$ git remote add ~~`したが、すでにremoteと紐付けられていたので、エラーが出ていた。* `$ git commit -m "hoge"` したらエラー(=`vender/bundle`は`git`管理できない)が出たので、`gitignoreファイル`に追記して解消した。```# Ignore all logfiles and tempfiles.(省略).byebug_history/vendor/*  ←ココに追記
```
参照サイト:[git-flowを試す - Qiita](https://qiita.com/tanishi/items/09e72c65c0a0c9e1cc10)```$ mkdir ディレクトリ名$ cd ディレクトリ名①新規でリポジトリを作る場合$ echo "hoge" >> README.md→ 「hoge」と記載があるREADME.mdファイルができる。$ git flow init$ git branch ←2つのブランチができている  * develop    master$ git branch -a  ←端末上にあるローカル, リモートブランチの全て  * develop    master    remotes/origin/master$ git remote add push名 https://github.com/~$ git remote -v  push名   https://github.com/~ (fetch)  push名   https://github.com/~ (push)$ git push --all ←最初だから全てのブランチをpush$ git branch -a* develop  master  remotes/origin/develop  remotes/origin/master$ git fetch$ git branch -a* develop  master  remotes/origin/develop  remotes/origin/feature/add_index.html  ←他人がリモートにpushしたブランチ  remotes/origin/master$ git checkout -b feature/add_index.html origin/feature/add_index.html→ git checkout -b 切り替えたいブランチ fetchで取得した参照するブランチ②git clone ~ する場合


```
conflict解消同じファイルの編集を他の人が `branch-B`で先にマージしていて、conflictが起こった場合の対処法```$ git branch  develop  feature/add_index.html* feature/branch-A  master$ git pull origin feature/branch-B
$ git branch  develop  feature/add_index.html* feature/branch-A  master$ git add .$ git commit -m "branch-Bとのconflict解消"[feature/branch-A a3dd1a1] branch-Bとのconflict解消$ git push
コンフリ起きた
マージできない。
pullする
ローカルで修正、コミュニケーション
後は、コミット、pushする
````feature`…新機能、追加機能の開発
`release`…リリースするものhttps://github.com/careerindex/file-uploader`hotfix`…バク対応する。→分岐元は`master`で、マージ先は`master`, `develop`ブランチになる。(git-flowだと基本的に`develop`に噛ませてから、`master`にマージするのが基本。本番でいきなり壊れることを防ぐため。)(github-flowだと、`master`にマージする。)

# rebaseコマンドからのコンフリクト解消```$ git fetch$ git branch -a  ansible  featrue/user-added-function  feature/partner-site-added-function  feature/test-user-added-function* master  remotes/origin/HEAD -> origin/master  remotes/origin/ansible  remotes/origin/featrue/user-added-function  remotes/origin/feature/partner-site-added-function  remotes/origin/master$ git pull ←ローカルのmasterを最新にする$ git log ←コミットが最新になっているか。確認する。$ git checkout [ブランチ名]$ git rebase master ←最新にしたmasterブランチへリベースするコンフリクトが起こるので下記のコマンドで解消していく。$ git rebase --continue$ git status ←しっかり選択されているか。確認する。$ git add .
$ git logコンフリクトを解消して、コミットが新しく更新のようになってるか確認$ git branch featrue/user-added-function* branch名  masterココで,リモートリポジトリの[branch名]へ変更をpushしたいが、このままだとエラーが起きる。理由としては下記。-------------------------------------------------------(1)リモートリポジトリは流れから ["D"] が来るだろうと期待している      A---B---C---”D” branch名     /D---E---F---G master-------------------------------------------------------(2)今回やろうとしている。rebaseは下記。              A'---B'---C'---D' branch名             /D---E---F---G master-------------------------------------------------------
無理やりブランチを上書きするコマンドが[force push]コマンドで-with-leaseオプションを付けたら少し安全なので付けて、上書きをする。
$ git push --force-with-lease
これでコンフリクトは解消する。これでマージリクエストができる。
```[git rebaseを初めて使った際のまとめ - Qiita](https://qiita.com/panti310/items/e0ec74b47c6c219f2a8b)[git rebase についてまとめてみた - Qiita](https://qiita.com/KTakata/items/d33185fc0457c08654a5)[git push -f をやめて —force-with-lease を使おう - Qiita](https://qiita.com/wMETAw/items/5f47dcc7cf57af8e449f)