Reading is one thing, but doing is how we truly learn. These exercises will walk you through the standard workflow on a safe, shared practice repository.
This guide is split into two parts. Master the basic exercises first to build a strong foundation before moving on to the advanced skills.
Before you begin, one person on the team should create a new, public, empty repository on GitHub named team-git-practice
. Do not add a README or any other files. Share the clone URL with everyone.
These exercises cover the essential day-to-day workflow.
Goal: To clone a repository, create a file, and make your first commit and push.
git clone <paste-the-repository-url-here>
cd team-git-practice
# On Windows PowerShell
New-Item your-name.md
# On Mac/Linux
touch your-name.md
Add Content: Open the new file and add a line like: Hello, my name is [Your Name]
. Save it.
git add .
git commit -m "feat: Add [Your Name]'s profile"
main
: For this first exercise, we will push directly to main
. This is the only time you should do this.
git push origin main
Goal: To practice the complete, safe workflow using a branch and a Pull Request.
git checkout main
git pull origin main
git checkout -b feature/add-hobby-[your-name]
Make Your Change: Open your personal .md
file and add a new line: My favorite hobby is...
. Save the file.
git add .
git commit -m "feat: Add hobby to [Your Name]'s profile"
git push origin feature/add-hobby-[your-name]
Open a Pull Request: Go to GitHub, open a PR, and assign a teammate to review it.
Goal: To learn how to work with a teammate on the same feature branch. This requires a partner!
Partner A:
git checkout -b feature/collaborate
and git push -u origin feature/collaborate
.Partner B:
git fetch
and git checkout feature/collaborate
.review.md
with some text.git add .
, git commit -m "feat: Add review file"
, git push origin feature/collaborate
.Partner A:
git pull origin feature/collaborate
. You should now see the review.md
file.These exercises cover more complex but crucial situations you will face.
Goal: To learn how to fix the most recent commit. This is useful if you made a typo in the commit message or forgot to include a file.
git checkout -b feature/amend-practice-[your-name]
My favorite food is...
. Save it.
git add .
git commit -m "feat: Add faverite food"
Notice the typo in “favorite”!
git commit --amend -m "feat: Add favorite food"
skills.md
and add a skill to it.git add skills.md
git commit --amend --no-edit
The --no-edit
flag adds the new file to your previous commit without changing the message.
Goal: To learn how to view the project’s state at a previous point in time.
git log --oneline
git checkout <paste-commit-hash-here>
You are now in a “detached HEAD” state. Look at your files to see how they existed in the past.
git checkout main
Goal: To learn how to combine multiple “work-in-progress” commits into a single, clean commit before opening a Pull Request.
git checkout -b feature/rebase-practice-[your-name]
git rebase -i HEAD~3
pick
on the second and third lines to squash
(or s
). Save and close.feat: Update profile with new details
. Save and close. Your three commits are now one.Goal: To understand and fix a merge conflict. This exercise requires a partner!
main
branch: git checkout main
and git pull origin main
.conflict-A
and conflict-B
). git checkout main
git pull
git checkout conflict-B
git merge main
<<<
, ===
, >>>
markers and choosing the final code. git add .
git commit
git push origin conflict-B
The PR can now be merged.
Goal: To learn how to safely undo a change that has already been merged into main
.
main
via a Pull Request.