AI Hints
Home›Git & GitHub Tutorial›Project: Teamwork
Git & GitHub · Lesson 121 of 144

Project: Working with a Teammate

Two people, one repository.

⏱ 2 min read▶ Video at 2:11:50🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

In this project, two people share one repository. Sam owns it on GitHub, and Alex is a collaborator. We'll watch both terminals, so you can see exactly how changes travel between them.

Project: Working with a Teammate
From the video: Project: Working with a Teammate
  • Two people, one repository
  • Sam's terminal and Alex's terminal
  • Watch changes travel

Alex joins

First, Alex clones the repository, and checks the log. Alex now has the full history, the same as Sam. Alex also sets their own name and email, so their commits are labelled correctly.

Alex
git clone https://github.com/sam/my-site.git
Cloning into 'my-site'...
done.
cd my-site
git log --oneline -n 2
f63a17a (HEAD -> main, origin/main, origin/HEAD) Link to about page
ef9c947 Add basic styles
git config user.name "Alex Kim"
git config user.email "alex@example.com"

Alex's feature

Alex works on a navigation bar, on a branch called nav. Commit, push the branch, and open a pull request on GitHub, asking Sam to review it.

Alex
git switch -c nav
Switched to a new branch 'nav'
echo '<nav>Home | About | Blog</nav>' > nav.html
git add nav.html
git commit -m "Add navigation bar"
[nav a2a56dc] Add navigation bar
 1 file changed, 1 insertion(+)
 create mode 100644 nav.html
git push -u origin nav
To https://github.com/sam/my-site.git
 * [new branch]      nav -> nav
branch 'nav' set up to track 'origin/nav'.

Sam reviews it

Sam wants to try Alex's branch before approving. Git fetch, then switch to nav. The new page is right there. It looks good, so Sam approves and merges the pull request on GitHub.

Sam
git fetch
From https://github.com/sam/my-site
 * [new branch]      nav        -> origin/nav
git switch nav
Switched to a new branch 'nav'
branch 'nav' set up to track 'origin/nav'.
cat nav.html
<nav>Home | About | Blog</nav>

Summary

A collaborator clones, works on a branch, and opens a pull request. The owner fetches it, tries it, and merges. Next, what happens when both of them change the same line.

Key takeaways
  • Alex: clone, branch, push
  • Sam: fetch, switch, review
  • Merge on GitHub
Next up: Project: A Team Conflict — pull, fix, push