#!/usr/bin/env bash
# Exercise 15.4: push to a remote repository.
# On GitHub you create the repository on the website, then copy its address, such as https://github.com/sara/profile.git.
# So that this script runs anywhere, the "GitHub" here is an empty repository in a folder. The commands are exactly the same.
set -e
export GIT_AUTHOR_NAME="Sara Khan" GIT_AUTHOR_EMAIL="sara@example.com"
export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
export GIT_CONFIG_GLOBAL=/dev/null  # ignore your own Git settings while the script runs
run() { local s="\$"; for a in "$@"; do if [[ $a == *" "* ]]; then s+=" \"$a\""; else s+=" $a"; fi; done; echo "$s"; "$@"; }
cd "$(mktemp -d)"
git init -q --bare github-profile.git
mkdir profile && cd profile
git init -q -b main
printf '<h1>Sara Khan</h1>\n' > index.html
git add . && git commit -q -m "Add profile page"

run git remote add origin ../github-profile.git
run git push -q -u origin main
run git remote -v
echo "# What the remote has now (on GitHub: the repository page, and a click on the commit):"
run git --git-dir=../github-profile.git log --oneline --stat main
