Skip to content

Instantly share code, notes, and snippets.

@officel
Created June 17, 2020 03:58
Show Gist options
  • Save officel/b1305c85200d88a1c2d06a0184a294e7 to your computer and use it in GitHub Desktop.
Save officel/b1305c85200d88a1c2d06a0184a294e7 to your computer and use it in GitHub Desktop.
Pro Git のブランチ機能 - ブランチでの作業の流れのFigure 28,29
#!/bin/bash
# see https://git-scm.com/book/en/v2/Git-Branching-Branching-Workflows
repo="test"
name="your_name"
mail="your@example.com"
# clean
rm -fr ${repo} ${repo}.git
# init bare repository
git init --bare ${repo}.git
# clone
git clone ${repo}.git
# into repo
cd ${repo}
# config
git config --local user.name "${name}"
git config --local user.email "${mail}"
git config --local alias.plog "log --pretty=format:'%C(yellow)%h %C(green)%cd %C(reset)%s %C(red)%d %C(cyan)[%an]' --date=format:'%t%Y/%m/%d %H:%M' --all --graph"
# common work
function cw () {
sleep 1
echo "----------"
echo "$1" >> $1
git add $1
git commit -m $1
git plog
}
# Let's start
cw "c0"
# my 1st commit
git push
cw "c1"
echo "c2 from c1 in iss91"
git checkout -b iss91
cw "c2"
echo "c3 from c1 in master"
git checkout master
cw "c3"
echo "c4 from c2 in iss91"
git checkout iss91
cw "c4"
echo "save hash for iss91v2"
C4HASH=`git rev-parse --short HEAD`
echo "c4 hash is $C4HASH"
cw "c5"
cw "c6"
echo "c7 from c4 in iss91v2"
git checkout -b iss91v2 $C4HASH
cw "c7"
cw "c8"
echo "c9 from c3 in master"
git checkout master
cw "c9"
cw "c10"
echo "c11 from c8 in iss91v2"
git checkout iss91v2
cw "c11"
echo "c12 from c10 in dumbidea"
git checkout -b dumbidea master
cw "c12"
cw "c13"
echo "merge dumbidea"
git checkout master
git merge dumbidea
# dumbidea は ff merge なのですんなり入る
# iss91v2 はメッセージを付けると自動化できる(つけないとコミットメッセージ入力になる)
git merge iss91v2 -m "Merge branch 'iss91v2'"
git plog
git push
git plog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment