Skip to content

Instantly share code, notes, and snippets.

@cu39
Last active November 3, 2015 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cu39/be34ba9d56b9c7dbebff to your computer and use it in GitHub Desktop.
Save cu39/be34ba9d56b9c7dbebff to your computer and use it in GitHub Desktop.
Create a git repo whose last commit has four parents
#!/bin/sh
GIT=$(which git)
TARGET_DIR="four-parents"
if [[ -d $TARGET_DIR ]]; then
echo $TARGET_DIR already exists.
exit 1
fi
$GIT init $TARGET_DIR && cd $TARGET_DIR
MSG_MASTER_1="1 on master"
echo "$MSG_MASTER_1" > master.txt
$GIT add -A && $GIT commit -m "$MSG_MASTER_1"
for BRANCH in alpha beta gamma
do
MSG="1 on $BRANCH"
$GIT checkout -b $BRANCH
echo "$MSG" > $BRANCH.txt
$GIT add -A && $GIT commit -m "$MSG"
$GIT checkout master
done
MSG_MASTER_2="2 on master"
echo "$MSG_MASTER_2" >> master.txt
$GIT commit -a -m "$MSG_MASTER_2"
$GIT merge -m "Merge branches 'alpha', 'beta', and 'gamma'" \
alpha beta gamma
$GIT log --oneline --graph --decorate
$GIT cat-file -p HEAD
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment