Git Demo: End-to-End Walkthrough
Overview
This demo covers:
- Installing Git
- Creating a local repository
- Making changes
- Committing changes
- Creating branches
- Switching branches
- Uploading to GitHub
- Creating and merging a Pull Request
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:
ABOUT.mddisappears- The file only exists on the feature branch
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
- Open the repository on GitHub
- Click Compare & pull request
- Verify:
- Base branch:
main - Compare branch:
feature/add-about-page - Enter:
- Title
- Description
- Click Create pull request
- Open the Pull Request
- Review the changes
- Click Merge pull request
- Confirm merge
- Install Git
- Configure Git identity
- Create repository
- Create files
- Commit changes
- Edit files
- Commit again
- Create branch
- Add feature
- Push to GitHub
- Create Pull Request
- Merge Pull Request
- Pull latest changes
- Clean up branches
- Distributed version control system
- Tracks changes to files over time
- Enables collaboration
- Allows rollback to previous versions
- Snapshot of changes
- Includes:
- Files
- Metadata
- Author
- Timestamp
- Message
- Independent line of development
- Safe place to test features
- Keeps main branch stable
- Request to merge code changes
- Used for:
- Code review
- Discussion
- Validation
- Approval workflows
11. Merge the Pull Request
In GitHub
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
Common Talking Points
What is Git?
What is a Commit?
What is a Branch?
What is a Pull Request?
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