Lab
Lab: Create Your First GitHub Repository
Lab: Create Your First GitHub Repository
Objective
Set up Git basics for this course, create your first local Git repository, push it to GitHub, and submit the repository URL.
Success Criteria
- Verify that
gitandghare installed. - Confirm or set your global Git name and email.
- Create a new lab folder named
git-github-first-repo. - Initialize a Git repository.
- Create a project
.gitignorefile before your first commit. - Create and commit a simple
notes.mdfile. - Make one additional change and create a second commit.
- Create a public GitHub repository with
gh repo create. - Push your commits to GitHub.
- Submit the GitHub repository URL.
Instructions
- Read the Git and GitHub primer.
Use the primer linked in this module as your reference. This lab only asks you to practice the smallest useful workflow.
- Check that Git and GitHub CLI are available.
git --version
gh --version
If either command is missing, ask your instructor for help before continuing.
- Check your Git identity.
git config --global user.name
git config --global user.email
If either command prints nothing, set your name and email:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
- Check that GitHub CLI is logged in.
gh auth status
If you are not logged in, run:
gh auth login
Follow the prompts in the browser.
- Create your lab folder.
mkdir -p ~/labs
cd ~/labs
mkdir git-github-first-repo
cd git-github-first-repo
- Initialize Git.
git init
- Create this repository's
.gitignorefile.
Every lab repository should include its own .gitignore before your first commit. This file tells Git which local files should not be committed or pushed to GitHub.
cat > .gitignore <<'EOF'
node_modules
.env
.DS_Store
Thumbs.db
EOF
- Verify that
.gitignoreexists.
ls -a
cat .gitignore
You should see .gitignore, and it should include node_modules.
- Create your first file.
echo "# My First GitHub Repository" > notes.md
echo "" >> notes.md
echo "Git saves checkpoints. GitHub stores pushed commits online." >> notes.md
- Check what Git sees.
git status
You should see .gitignore and notes.md ready to be added.
- Make your first commit.
git add .
git commit -m "Create first GitHub practice notes"
git branch -M main
- Make one more change.
echo "" >> notes.md
echo "I created a .gitignore before my first commit." >> notes.md
- Make your second commit.
git status
git add .
git commit -m "Add Git ignore note"
- Check your commit history.
git log --oneline
You should see two commits.
- Create a public GitHub repository and push your work.
gh repo create git-github-first-repo --public --source=. --remote=origin --push
- Verify the GitHub remote.
git remote -v
- Open the repository in your browser.
gh repo view --web
Required Deliverables
Your GitHub repository must include:
notes.md.gitignore- at least two commits
- a public GitHub repository URL
Submit Your Lab With GitHub
Open your repository in the browser:
gh repo view --web
Copy the GitHub repository URL from your browser and submit that URL with your lab submission.