Git & GitHub Mastery: Workflows & CI/CD
Back to Git Fundamentals

Scenario 1 — Set Up a Git Repo + Push to GitHub

Create a new project, initialize Git, push to GitHub. The basic loop everyone needs cold.

37 minutesAssignment
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

The brief

Start a new project from scratch. Initialize Git, make commits, push to GitHub. Then clone it on another machine (or another folder) to prove it works.

Step 1: Local setup (10 min)

mkdir my-first-repo
cd my-first-repo

git init
# Initialized empty Git repository in /path/to/my-first-repo/.git/

Configure your identity (one-time):

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

# For new repos, default branch name
git config --global init.defaultBranch main

Step 2: Create some content (5 min)

echo "# My First Repo" > README.md
echo "*.pyc
__pycache__/
.env
.venv/" > .gitignore

mkdir src
echo "def hello():
    print('Hello, Git!')" > src/main.py

Step 3: First commit (5 min)

git status
# Untracked files:
#   .gitignore
#   README.md
#   src/

git add .
git status                        # all green now

git commit -m "Initial commit: README, gitignore, hello script"
git log
# commit abc123... (HEAD -> main)
# Author: Your Name <you@example.com>
# Date: ...
#   Initial commit: README, gitignore, hello script

Step 4: Authenticate with GitHub (5 min)

Before pushing you need credentials. Pick ONE:

  • HTTPS + PAT (simplest): create a Personal Access Token at github.com → Settings → Developer settings → Personal access tokens → Tokens (classic) → Generate new token (scope repo). Use it as your password when Git prompts.
  • SSH key: ssh-keygen -t ed25519 -C "you@example.com" then add ~/.ssh/id_ed25519.pub at github.com → Settings → SSH and GPG keys → New SSH key. Verify with ssh -T git@github.com.

Then create the repo:

Step 5: Create GitHub repo (5 min)

Option A: Via web

  1. Go to github.com → New repository.
  2. Name: my-first-repo.
  3. Don't initialize with README (you already have one locally).
  4. Create.

Option B: Via gh CLI

gh repo create my-first-repo --public --source=. --remote=origin --push

This creates AND pushes. Skip to step 7 (Verify).

Step 6: Add remote and push (5 min)

If you used Option A:

git remote add origin git@github.com:yourname/my-first-repo.git
git remote -v
# origin git@github.com:yourname/my-first-repo.git (fetch)
# origin git@github.com:yourname/my-first-repo.git (push)

git push -u origin main
# -u sets up tracking; future pushes can just be `git push`

Step 7: Verify on GitHub (5 min)

Refresh github.com/yourname/my-first-repo. You should see:

  • README.md displayed.
  • src/main.py.
  • 1 commit.

Step 8: Clone elsewhere (10 min)

In a different directory (or another machine):

cd /tmp
git clone git@github.com:yourname/my-first-repo.git
cd my-first-repo
ls
# .git/  .gitignore  README.md  src/

cat README.md
# # My First Repo

Your repo is now in two places, synced via GitHub.

Step 9: Make a change and push (5 min)

# Edit README.md (or any file)
echo "
## Description
A learning project for Git." >> README.md

git status
git diff
git add README.md
git commit -m "Add description to README"
git push

Refresh GitHub; the change appears.

Step 10: Pull on the other clone

In the OTHER directory:

cd /tmp/my-first-repo
git pull
cat README.md
# Now shows the updated content

Deliverables

Submission contract: paste your GitHub repo URL into the submission notes. Reviewer checks: ≥2 commits on main, README renders, and a second clone is in sync.

100-pt rubric: repo initialized + identity configured (20) / ≥2 commits with clean messages (20) / remote added + pushed (20) / second clone proves sync (20) / .gitignore excludes .env/.venv (20).

paste your GitHub repo URL into the submission notes. Reviewer checks: ≥2 commits on main, README renders, and a second clone is in sync.

repo initialized + identity configured (20) / ≥2 commits with clean messages (20) / remote added + pushed (20) / second clone proves sync (20) / .gitignore excludes .env/.venv (20).

paste your GitHub repo URL into the submission notes. Reviewer checks: ≥2 commits on main, README renders, and a second clone is in sync.

repo initialized + identity configured (20) / ≥2 commits with clean messages (20) / remote added + pushed (20) / second clone proves sync (20) / .gitignore excludes .env/.venv (20).

  • GitHub repo URL.
  • Locally: git log --oneline shows ≥ 2 commits.
  • README is displayed nicely on GitHub.
  • Both clones synced.

What you'll learn

  • The basic Git → GitHub workflow.
  • git init, git add, git commit, git push.
  • git remote to connect local to GitHub.
  • git clone for a fresh copy.
  • git pull to sync.
  • .gitignore to skip unwanted files.

Stretch

  • Add a LICENSE file (MIT, Apache, etc.).
  • Add a CI workflow (.github/workflows/ci.yml) that runs a placeholder check.
  • Add issue and PR templates.
  • Add a status badge to the README.

Track your learning progressFree

Sign in or enroll free to mark this assignment as complete, save your progress, and earn certificates.