GitHub

Hands-On

Demo

In this demo, we will:

  1. Set up Git configuration and GitHub authentication
  2. Scenario 1: Create a repository on GitHub and clone to local computer
  3. Scenario 2: Create a repository locally with SSH authentication and push to GitHub
  4. Practice essential Git commands for both workflows
  5. Test collaboration features and repository functionality
  6. Clean up resources including repositories and SSH keys

Agenda

cd Desktop
mkdir github-demo
cd github-demo
ls
git config --global user.name "Deepak Dubey"
git config --global user.email "learnpde@gmail.com"
git --version

Create Personal access tokens (classic)

Generate new token (classic)

Lab Demo Token

Generate token

Personal access tokens (classic)

demo-repo-scenario1

Add gitignore

demo-repo-scenario1

git clone URL 

git clone https://github.com/learnpde/demo-repo-scenario1.git
cd demo-repo-scenario1
ls -la
git status
echo "console.log('Hello from Scenario 1!');" > app.js
cat > package.json << EOF
{
  "name": "demo-repo-scenario1",
  "version": "1.0.0",
  "description": "Demo repository for GitHub hands-on lab",
  "main": "app.js",
  "scripts": {
    "start": "node app.js"
  }
}
EOF
git status
git add app.js package.json
git commit -m "Add initial application files and package.json"
git push origin main
export GITHUB_TOKEN=your_token_here
git push "https://${GITHUB_TOKEN}@github.com/learnpde/demo-repo-scenario1.git" main

Verify

2nd Repository - Use SSH Keys

git log --oneline
mkdir -p ~/.ssh
chmod 700 ~/.ssh
cd ~/.ssh
ssh-keygen -t ed25519 -C "learnpde@gmail.com" -f ~/.ssh/github-demo
cat ~/.ssh/github-demo.pub

Add new SSH Key

Lab Demo SSH Key
chmod 600 ~/.ssh/github-demo
chmod 644 ~/.ssh/github-demo.pub
ssh-add ~/.ssh/github-demo
ssh -T git@github.com
cd ~/Desktop/github-demo
mkdir demo-repo-scenario2
cd demo-repo-scenario2
git init
cat > README.md << EOF
# Demo Repository - Scenario 2

This repository demonstrates creating a local Git repository first, then pushing to GitHub.

## Features
- Local-first development approach
- Essential Git command demonstration
- GitHub integration workflow

## Getting Started
Run the application with:
\`\`\`
python main.py
\`\`\`
EOF

Add README.md

cat > main.py << EOF
#!/usr/bin/env python3
"""
Demo application for GitHub hands-on lab
Scenario 2: Local repository created first
"""

def main():
    print("Hello from Scenario 2!")
    print("This repository was created locally first.")
    
    # Demonstrate some basic functionality
    numbers = [1, 2, 3, 4, 5]
    squared = [n**2 for n in numbers]
    print(f"Original numbers: {numbers}")
    print(f"Squared numbers: {squared}")

if __name__ == "__main__":
    main()
EOF
cat > .gitignore << EOF
# Python
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
env/
venv/
.venv/

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db
EOF
git add .
git commit -m "Initial commit: Add README, main application, and gitignore"

Create 2nd repository

demo-repo-scenario2
Hands-on demo repository created locally first

Check Nothing

git remote add origin git@github.com:learnpde/demo-repo-scenario2.git
git branch -M main
git remote -v
git push -u origin main

Verify

Feature Branches

cd ../demo-repo-scenario1
git checkout -b feature/add-functions
git switch -c feature/add-functions

"git checkout -b" to create and switch to new branch

cat > utils.js << EOF
// Utility functions for the demo application

function calculateSum(numbers) {
    return numbers.reduce((sum, num) => sum + num, 0);
}

function calculateAverage(numbers) {
    return numbers.length > 0 ? calculateSum(numbers) / numbers.length : 0;
}

function findMax(numbers) {
    return Math.max(...numbers);
}

module.exports = {
    calculateSum,
    calculateAverage,
    findMax
};
EOF
cat > app.js << EOF
const { calculateSum, calculateAverage, findMax } = require('./utils');

console.log('Hello from Scenario 1!');

// Demo the utility functions
const numbers = [10, 25, 30, 15, 40];
console.log('Numbers:', numbers);
console.log('Sum:', calculateSum(numbers));
console.log('Average:', calculateAverage(numbers));
console.log('Maximum:', findMax(numbers));
EOF
git add .
git commit -m "Add utility functions and update main application"
git push -u origin feature/add-functions

Pull Request

Create Pull Request

Add utility functions and update main application

Open a pull request

Add Detailed Description here

Merge pull request

Merge pull request #1 from learnpde/feature/add-functions

Commit message

Merged

Verify

git switch main
ls -la
git pull origin main
git branch -d feature/add-functions

Update Directly at Source

## Recent Updates
- Added collaborative workflow demonstration
- Updated: [Current Date]

demo-repo-scenario2

Commit changes

Update README with collaboration info

Check

cd ../demo-repo-scenario2
cat README.md
git pull origin main
cat README.md
git config --list

Clone to another folder

cd ..
git clone https://github.com/learnpde/demo-repo-scenario1.git test-clone
cd test-clone

Test

node app.js
cd ../demo-repo-scenario2
python3 main.py

Test

Clean Up

cd ..
rm -rf demo-repo-scenario1 demo-repo-scenario2 test-clone

Delete demo-repo-scenario1

Delete demo-repo-scenario1

Delete demo-repo-scenario1

Delete demo-repo-scenario1

Delete demo-repo-scenario1

learnpde/demo-repo-scenario1

Delete demo-repo-scenario2

Delete demo-repo-scenario2

Delete demo-repo-scenario2

learnpde/demo-repo-scenario2

Delete Personal access tokens (classic)

Delete SSH Keys on GitHub 

Delete SSH Keys on GitHub 

rm ~/.ssh/github-demo
rm ~/.ssh/github-demo.pub

Delete SSH Keys

ls github-demo github-demo.pub

🙏

Thanks

for

Watching

GitHub - Hands-On Demo

By Deepak Dubey

GitHub - Hands-On Demo

GitHub - Hands-On Demo

  • 13