Git Demo: End-to-End Walkthrough

Overview

This demo covers:


1. Install Git

Windows

Install Git using Winget:

winget install --id Git.Git -e

Check the install:

git --version

Configure your Git identity:

git config --global user.name "Michael Whitehouse"
git config --global user.email "you@example.com"

Check configuration:

git config --list

2. Create a Folder and Initialise a Repository

Create a new folder:

mkdir git-demo
cd git-demo

Initialise Git:

git init

Check repository status:

git status

Expected output:

On branch main

No commits yet
nothing to commit

3. Create Some Files

Create a README file:

"# Git Demo" | Out-File README.md

Create a Python file:

"print('Hello from Git')" | Out-File app.py

Check status:

git status

Expected output:

Untracked files:
  README.md
  app.py

4. Stage and Commit Files

Stage files:

git add README.md app.py

Commit changes:

git commit -m "Initial commit"

View commit history:

git log --oneline

Example output:

3f4c2d1 Initial commit

5. Make a Change

Append a new line to the Python file:

"print('This is my second line')" | Out-File app.py -Append

Check differences:

git diff

Expected output:

+ print('This is my second line')

Stage and commit the change:

git add app.py
git commit -m "Update app output"

Check history again:

git log --oneline

6. Create a Branch

Create a new branch:

git branch feature/add-about-page

Switch to the branch:

git switch feature/add-about-page

Alternative one-line method:

git switch -c feature/add-about-page

Check current branches:

git branch

Example output:

* feature/add-about-page
  main

7. Make Changes on the Branch

Create a new file:

"# About this project" | Out-File ABOUT.md
"This is a simple Git demo repo." | Out-File ABOUT.md -Append

Stage and commit:

git add ABOUT.md
git commit -m "Add about page"

View commit history:

git log --oneline

8. Switch Back to Main

Switch back:

git switch main

List files:

dir

Notice:

Switch back to the branch:

git switch feature/add-about-page

9. Upload to GitHub

Option A: GitHub CLI

Install GitHub CLI:

winget install --id GitHub.cli -e

Authenticate:

gh auth login

Create a GitHub repository from the current folder:

gh repo create git-demo --public --source=. --remote=origin --push

Option B: GitHub Website

Step 1

Go to GitHub and create an empty repository.

Example:

https://github.com/YOURUSERNAME/git-demo

Step 2

Connect local Git repo to GitHub:

git remote add origin https://github.com/YOURUSERNAME/git-demo.git

Verify remotes:

git remote -v

Push the main branch:

git push -u origin main

Push the feature branch:

git push -u origin feature/add-about-page

10. Create a Pull Request

Using GitHub CLI

gh pr create --base main --head feature/add-about-page --title "Add about page" --body "Adds an ABOUT.md file to describe the project."

Using GitHub Website

  1. Open the repository on GitHub
  2. Click Compare & pull request
  3. Verify:
    • Base branch: main
    • Compare branch: feature/add-about-page
  4. Enter:
    • Title
    • Description
  5. Click Create pull request

  6. 11. Merge the Pull Request

    In GitHub

    1. Open the Pull Request
    2. Review the changes
    3. Click Merge pull request
    4. Confirm merge

    5. Update Local Repository

      Switch to main:

      git switch main

      Pull latest changes:

      git pull

      12. Clean Up the Branch

      Delete local branch:

      git branch -d feature/add-about-page

      Delete remote branch:

      git push origin --delete feature/add-about-page

      Useful Demo Commands

      Repository Status

      git status

      Commit History

      git log --oneline

      View Branches

      git branch

      Compare Changes

      git diff

      Show Remote Repositories

      git remote -v

      Suggested Live Demo Flow

      1. Install Git
      2. Configure Git identity
      3. Create repository
      4. Create files
      5. Commit changes
      6. Edit files
      7. Commit again
      8. Create branch
      9. Add feature
      10. Push to GitHub
      11. Create Pull Request
      12. Merge Pull Request
      13. Pull latest changes
      14. Clean up branches

      15. Common Talking Points

        What is Git?

        • Distributed version control system
        • Tracks changes to files over time
        • Enables collaboration
        • Allows rollback to previous versions

        What is a Commit?

        • Snapshot of changes
        • Includes:
          • Files
          • Metadata
          • Author
          • Timestamp
          • Message

        What is a Branch?

        • Independent line of development
        • Safe place to test features
        • Keeps main branch stable

        What is a Pull Request?

        • Request to merge code changes
        • Used for:
          • Code review
          • Discussion
          • Validation
          • Approval workflows

        Extra Commands for Questions

        Clone a Repository

        git clone https://github.com/YOURUSERNAME/git-demo.git

        See Commit Details

        git show

        Rename Current Branch

        git branch -m main

        Undo Unstaged Changes

        git restore app.py

        Undo Last Commit (Keep Files)

        git reset --soft HEAD~1

        Fetch Changes Without Merging

        git fetch

        Pull Latest Changes

        git pull