Git & GitHub Lab Program
1. Objective
To learn the basics of version control using Git and collaboration using GitHub.
2. Prerequisites
• Git installed on your system (https://git-scm.com/downloads)
• A GitHub account (https://github.com/)
• Basic knowledge of command line (Terminal / Git Bash)
3. Lab Tasks
Task 1: Configure Git
git config --global user.name "Your Name" git config --global user.email
"[email protected]" git config --list Explanation: This sets your name and email for all
commits.
Task 2: Create a Local Repository
mkdir my-first-repo cd my-first-repo git init Explanation: • mkdir → Creates a folder • cd → Enters
the folder • git init → Makes it a Git repository
Task 3: Create and Commit a File
echo "Hello Git" > file1.txt git status git add file1.txt git commit -m "First commit - Added file1.txt"
Explanation: • git status → Shows changes • git add → Stages file • git commit → Saves it in Git
history
Task 4: Create a GitHub Repository
1. Log in to GitHub 2. Click New Repository 3. Name it my-first-repo 4. Keep it public and empty
(don’t add README) 5. Copy repository HTTPS URL
Task 5: Connect Local Repo to GitHub
git remote add origin https://github.com/username/my-first-repo.git git branch -M main git push -u
origin main Explanation: Links local repo to GitHub and pushes code online.
Task 6: Make a Change and Push
echo "Second line" >> file1.txt git add file1.txt git commit -m "Updated file1.txt" git push Explanation:
• >> appends text • Push changes to GitHub
Task 7: Clone a Repository
cd .. git clone https://github.com/username/my-first-repo.git Explanation: Creates a local copy of
any GitHub repo.
Task 8: Branching and Merging
git checkout -b new-feature echo "Feature added" > feature.txt git add feature.txt git commit -m
"Added new feature" git checkout main git merge new-feature git push Explanation: • Create a
branch for new work • Merge into main after completion
4. Expected Output
• Local Git repository initialized
• Changes committed and pushed to GitHub
• Students able to pull, push, and merge code