Skip to content

Stat386-Winter-2026/Git_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

In-class demo and walkthrough (Git + GitHub)

This is written as an instructor script you can run live. It starts with SSH verification, then does a quick local Git demo, then transitions into the pair labs.

0. Pre-flight (2 minutes)

Ask students to open a terminal in a working directory where they can create a new folder. Quick sanity checks:

git --version
ssh -V

If Git is missing, have them install Git and restart their terminal.

1. Verify GitHub SSH (10 minutes)

1.1 The check

ssh -T git@github.com

Expected outcomes:

  • If it prints a greeting and mentions successful authentication, they are good.
  • If it asks to confirm a host fingerprint, type yes.
  • If it says permission denied, continue below.

1.2 If permission denied: fix checklist

  1. Check for an existing key:
ls -al ~/.ssh

Look for id_ed25519 and id_ed25519.pub (or id_rsa / id_rsa.pub). 2) If no key exists, generate one:

ssh-keygen -t ed25519 -C "your_email@example.com"

Accept defaults. Use a passphrase if you want, but warn that it adds prompts unless they use a keychain. 3) Start agent and add the key:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
  1. Copy the public key and add it to GitHub macOS:
pbcopy < ~/.ssh/id_ed25519.pub

Linux:

xclip -selection clipboard < ~/.ssh/id_ed25519.pub

Windows Git Bash:

cat ~/.ssh/id_ed25519.pub

Then GitHub: Settings → SSH and GPG keys → New SSH key → paste. 5) Re-test:

ssh -T git@github.com

Optional debugging (when someone is still stuck):

ssh -vT git@github.com

2. Clone vs fork (5 minutes)

Say this out loud:

  • Clone: downloads a repo to your machine.
  • Fork: makes a copy on GitHub under your account. Two common scenarios:
  1. You have write access to the repo (class repo, your own repo): clone it directly.
  2. You do not have write access (open source, partner repo): fork on GitHub, then clone your fork.

2.1 For today's exercise

  1. Go to: https://github.com/Stat386-Winter-2026/Git_demo.
  2. Determine whether you should clone directly or fork the repo.
  3. Walk through the fork + clone steps:
  • Click Fork in GitHub, keep the default settings.
  • Copy the SSH URL from your fork (not the instructor repo).
  • In the terminal:
git clone git@github.com:<student-username>/Git-demo.git
cd Git-demo
git remote -v
  1. origin now points to your fork. If you need the upstream link, add it with git remote add upstream git@github.com:Stat386-Winter-2026/Git_demo.git.
  2. You can still pull upstream changes later with git fetch upstream && git merge upstream/main.

3. Quick local Git demo (8 to 10 minutes)

3.1 Create a fresh demo repo

First navigate to a working directory you want to create a folder in and then:

mkdir git_demo
cd git_demo
git init

Explain: git init creates the hidden .git directory, the local database.

3.2 Add a file and commit

Create hello.py:

print('Hello, Git!')

Then:

git status
git add hello.py
git commit -m "Initial commit: add hello.py"

3.3 Make a change, inspect diff, commit

Append:

print('Learning version control')

Then:

git status
git diff
git add hello.py
git commit -m "Add learning message"

3.4 View history

git log --oneline

Optional (more visual):

git log --oneline --graph --all

3.5 Restore a previous version of a file

Copy the first commit hash from git log --oneline (the older one), then:

cat hello.py
git checkout <OLD_COMMIT_HASH> -- hello.py
cat hello.py

Bring it back to the latest:

git checkout <MOST_RECENT_COMMIT_HASH> -- hello.py
cat hello.py

3.6 .gitignore quick win

printf "*.log\n" > .gitignore
echo "temp" > temp.log
git status

Explain: ignored files do not show up as untracked, which protects you when using git add ..

3.7 Branch and merge

git checkout -b feature

Add another line to hello.py:

print('Working on a new feature')

Commit and show graph:

git add hello.py
git commit -m "Add feature print"
git log --oneline --graph --all

Merge into main:

cat hello.py
git checkout master
cat hello.py
git merge feature

3.8 Merge Conflict demo

Create a new branch to simulate a conflict.

git checkout -b test_merge
git checkout master

In master, change the last line of hello.py to:

print('Working on an old feature')
git add hello.py
git commit -m "Modify feature line in master"
git checkout test_merge

On test_merge, change the last line of hello.py to:

print('Working on an exciting feature')
touch testing.txt
git add .
git commit -m "Modify feature line in test_merge"
git checkout master
git merge test_merge

This will produce a conflict. Let's explore.

cat hello.py
git status
ls -al

Here is how to abort the merge:

git merge --abort
git status
ls -al

Now, let's try resolving it. Repeat the steps to create the conflict, then:

git merge test_merge

Now let's resolve it by editing hello.py to the desired final state. After editing:

git add hello.py
git commit -m "Resolve merge conflict between master and test_merge"
git log --oneline --graph --all

4. Pair lab 1: Pull requests

Use the provided notebook instructions in CLass Lab - Pull Requests.

5. Pair lab 2: Conflicts (20 to 25 minutes)

Use the provided notebook instructions in CLass Lab - Conflicts.

Instructor talking points

  • Conflicts happen when Git cannot safely auto-merge.
  • The conflict markers show two competing versions.
  • The resolution is just: edit to the correct final file, stage, commit.

Common student pitfalls

  • Forgetting to git pull before merging
  • Resolving conflict in GitHub UI but not pulling locally
  • Leaving conflict markers in the file

6. Wrap-up

Exit ticket prompts:

  1. Explain clone vs fork in one sentence.
  2. Paste the first line of ssh -T git@github.com.
  3. What caused a conflict today and what did you do to resolve it?

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors