2 Git & GitHub
This chapter walks through the core Git workflow used throughout the course. You will initialize a repository, set your Git identity, create and switch to feature branches, make commits, push changes to GitHub, and open a pull request. These steps reflect the best practices introduced in Sessions 1–2.
2.1 Initialize Repository (Starting Fresh)
# Initialize repo (if starting fresh on local computer)
git init
git branch -M main
git remote add origin https://github.com/<you>/tools-in-action-yourlastname.git
# For privacy (on local computer)
git config user.name "your_chosen_nick_name"
git config user.email "12345678+your_github_name@users.noreply.github.com"
git add .
git commit -m "chore: scaffold Quarto book"
This shell block initializes a new Git repository and prepares it for use with GitHub. git init creates the repository, and git branch -M main ensures the default branch is named main. The git remote add origin … command links the local repo to a GitHub repository so changes can be pushed online.
The identity settings (git config user.name and git config user.email) configure a privacy-safe username and email for your commits. Finally, git add . stages all current files, and git commit -m “chore: scaffold Quarto book” creates the first commit containing the project scaffold.
2.2 Create a Feature Branch, Make a Change, Commit, Push, Open PR
git checkout -b feat/sql-chapter
# Stage and commit a file (you may also simply run: git add .)
git add book/05_sql_sqlite.qmd
git commit -m "docs(sql): first join examples"
# Push the branch to GitHub
git push -u origin feat/sql-chapter
This set of commands demonstrates how to create and publish a feature branch in Git. git checkout -b feat/sql-chapter creates a new branch and switches to it. After making edits, git add stages the updated file, and git commit records the change with a descriptive message.
Finally, git push -u origin feat/sql-chapter uploads the new branch to GitHub and sets it as the upstream branch, enabling future pushes with a simple git push. This workflow is the standard pattern for developing features and preparing pull requests.
```