# Create an empty repository
git init WorkingWithBranches
cd       WorkingWithBranches

# Create an executable shell script HelloWorld.sh
cat > HelloWorld.sh <<'EOF'
#!/usr/bin/bash

echo "Hello World"
EOF
chmod +x HelloWorld.sh

# First commit on master branch
git add HelloWorld.sh
git commit -m "Hello World"

# Create new branch HelloWorldForCats
git branch HelloWorldForCats
git branch

# Switch to branch HelloWorldForCats
git switch HelloWorldForCats
git branch

# * git switch / restore separate functionality of the overloaded git checkout command
# Add feature helloWorldForCats to script HelloWorld.sh

cat > HelloWorld.sh <<'EOF'
#!/usr/bin/bash

case "$1" in
  cats) echo "Hello World for Cats" ;;
     *) echo "Hello World"          ;;
esac
EOF

# Commit changes to branch helloWorldForCats
git commit -m "Hello World for Cats" HelloWorld.sh

# Return to master branch
git switch master

# Create and switch to new branch HelloWorldForDogs
git switch -c HelloWorldForDogs
git branch

# Add feature helloWorldForDogs to script HelloWorld.sh
cat > HelloWorld.sh <<'EOF'
#!/usr/bin/bash

case "$1" in
  dogs) echo "Hello World for Dogs" ;;
     *) echo "Hello World"          ;;
esac
EOF

# Commit changes to branch helloWorldForDogs
git commit -m "Hello World for Dogs" HelloWorld.sh

# Return to master branch
git switch master

# Review history
git log
git log --all --graph

# Integrate feature developed on branch HelloWorldForCats
git merge HelloWorldForCats

# Integrate feature developed on branch HelloWorldForDogs
git merge HelloWorldForDogs

# Review repository status
git status

# Conflict markers in the script HelloWorld.sh help to resolve the conflicts
cat > HelloWorld.sh <<'EOF'
#!/usr/bin/bash

case "$1" in
  cats) echo "Hello World for Cats" ;;
  dogs) echo "Hello World for Dogs" ;;
     *) echo "Hello World"          ;;
esac
EOF

# Review changes
git diff

# Continue integrating feature from branch HelloWorldForDogs
git add HelloWorld.sh
git merge --continue

# Merge can be aborted, when unable to resolve conflicts: git merge --abort

# Review history
git log --all --graph --oneline

# Remove unneeded branches
git branch --delete HelloWorldForCats HelloWorldForDogs
git branch

# Review history
git log --all --graph --oneline

# Caution: Branches are not transferred to remote servers by default
