LoginSignup
4
5

More than 5 years have passed since last update.

GitHub初心者が1人でコンフリクトの解決を試してみた(前編)

Last updated at Posted at 2016-07-02

1人でもチーム開発を想定したGitの学習はできる?

Gitは基本的に1人の開発ではなく、複数人で開発する場合に利用しますよね。独学でも、最終的には誰かと一緒に開発をしたいから学習していると思います。

そういったときに起こるのが、「はい、二人組つくってー」問題です。一緒に学習する人がいる人は良いのですが、1人寂しく学習している人(私です)にとっては、プルリクエストやコンフリクトは未知の領域です。

ローカルリポジトリを複数作ってコンフリクト(競合)を発生させる

自分のパソコンにローカルのリポジトリを複数作り、同じファイルを編集しましょう。コンフリクトします!やったね!

やり方

  1. GitHub で新しいリポジトリを作成
  2. ローカルにクローン(1つ目)
  3. 新しいファイルを作成してコミット&プッシュ
  4. ローカルにクローン(2つ目)
  5. 新しいブランチを作成してファイルを変更 × 2回
  6. プルリクエストを作成 × 2回
  7. プルリクエストをマージ(1つ目)
  8. コンフリクト発生!

1.GitHub で新しいリポジトリを作成

スクリーンショット 2016-07-02 15.32.44.png

スクリーンショット 2016-07-02 15.33.37.png

2.ローカルにクローン(1つ目)

cd ~/Desktop/
mkdir repo1
cd repo1
git clone https://~.git
cd [リポジトリ名]

スクリーンショット 2016-07-02 15.34.51.png

3.新しいファイルを作成してコミット&プッシュ

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新しいファイル</title>
</head>
<body>

</body>
</html>
git add index.html
git commit -m "create index.html"
git push origin master

4.ローカルにクローン(2つ目)

cd ~/Desktop/
mkdir repo2
cd repo2
git clone https://~.git
cd [リポジトリ名]

5.新しいブランチを作成してファイルを変更 × 2回

repo1

git checkout -b repo1
index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>repo1で変更</title>
</head>
<body>

</body>
</html>
git add index.html
git commmit -m "repo1での変更"
git push origin repo1:repo1

repo2

git checkout -b repo2
index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>repo2で変更</title>
</head>
<body>

</body>
</html>
git add index.html
git commmit -m "repo2での変更"
git push origin repo2:repo2

6.プルリクエストを作成 × 2回

スクリーンショット 2016-07-02 15.47.16.png

repo1

スクリーンショット 2016-07-02 15.47.55.png

repo2

この時点でコンフリクトが発生するのがわかります。(Can't automatically merge.)

スクリーンショット 2016-07-02 15.48.36.png

7.プルリクエストをマージ(1つ目)

スクリーンショット 2016-07-02 15.50.27.png

8.コンフリクト発生!

スクリーンショット 2016-07-02 15.51.48.png

まとめ

1人でもコンフリクトを発生させることができました!コンフリクトが発生して嬉しい数少ない機会だと思います。

長くなったので、後編でコンフリクトを解決します。

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5