1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GitHub再入門(ブランチ操作)

Last updated at Posted at 2018-04-15

ブランチ操作

1. ブランチ作成
img-branch.png

2. ブランチ切り替え
img-checkout.png

3. ブランチ削除
img-branch-d.png

4. ブランチマージ

4-1. fast-forward
img-merge.png

4-2. non-fast-forward
img-manual-merge.png

1. ブランチ作成

cmd
rm -rf .git/
git init
echo "# create(master)" > file_1.md
git add .
git commit -m "create@master"
echo "# update(master)" >> file_1.md
git commit -a -m "update@master"
git branch issue-1
git branch

img-branch.png

branch.png

2. ブランチ切り替え

cmd
git checkout issue-1
git branch

img-checkout.png

checkout.png

3. ブランチ削除

cmd
git branch -d issue-1
git branch

img-branch-d.png

branch-d.png

4. ブランチマージ

4-1. fast-forward

1. ブランチ(issue-1)作成

cmd
rm -rf .git/
git init
echo "# create(master)" > file_1.md
git add .
git commit -m "create@master"
echo "# update(master)" >> file_1.md
git commit -a -m "update@master"
git branch issue-1
git branch
git checkout issue-1

img-branch.png
img-checkout.png

2. issue-1の編集&マージ

cmd
echo "# update(issue-1)" >> file_1.md
git commit -a -m "update@issue-1"
cat file_1.md
git checkout master
cat file_1.md
git merge issue-1
cat file_1.md
git branch -d issue-1
git log --graph

img-merge-2.png
img-branch-d.png

merge.png

4-2. non-fast-forward

1. ブランチ(issue-1、issue-2)作成

cmd
rm -rf .git/
git init
echo "# create(master)" > file_1.md
git add .
git commit -m "create@master"
echo "# update(master)" >> file_1.md
git commit -a -m "update@master"
git branch issue-1
git branch issue-2
git branch
git checkout issue-1

non-fast-1.png

2. issue-1の編集&マージ

cmd
echo "# update(issue-1)" >> file_1.md
git commit -a -m "update@issue-1"
cat file_1.md
git checkout master
cat file_1.md
git merge issue-1
cat file_1.md
git branch -d issue-1

non-fast-2.png

3. issue-2の編集&マージ → 競合

cmd
git checkout issue-2
echo "# update(issue-2)" >> file_1.md
git commit -a -m "update@issue-2"
cat file_1.md
git checkout master
git merge issue-2
cat file_1.md

non-fast-3.png

img-conflictpng.png

4. issue-2競合の解消&マージ

cmd
vi file_1.md
git commit -a -m "manual merge"
git branch -d issue-2
git log --graph

non-fast-4.png

manual-merge.png

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?