Git and GitHub Practice: Self-Test and Exercises
Practice is the best way to learn Git and GitHub. Use these exercises to test your skills and reinforce what you’ve learned.
Basic Git Tasks
- Create a New Repository
- Initialize a new Git repository and make your first commit.
- Stage and Commit Changes
- Edit a file, stage it, and commit with a message.
- Undo Changes
- Unstage a file (
git restore --staged <file>
) - Amend your last commit (
git commit --amend
) - Revert a commit (
git revert <commit-hash>
)
Branching and Merging
- Create and Switch Branches
git checkout -b feature-branch
- Merge Branches
- Merge your feature branch into
main
and resolve any conflicts. - Delete Branches
git branch -d feature-branch
Working with Remotes
- Add a Remote and Push
git remote add origin <url>
git push -u origin main
- Pull Changes
git pull origin main
- Handle Merge Conflicts
- Practice resolving a conflict after pulling remote changes.
GitHub Practice
- Fork a Repository
- Fork a public repo and clone it locally.
- Submit a Pull Request
- Make a change and open a pull request to the original repo.
- Open and Close Issues
- Create an issue and close it after resolving.
- Assign Reviewers and Labels
- Assign a teammate to review your pull request and add labels.
Self-Test Checklist
- Can you create and clone repositories?
- Can you stage, commit, and push changes?
- Can you create, merge, and delete branches?
- Can you resolve merge conflicts?
- Can you fork a repo and submit a pull request?
- Can you use issues and project boards?
Further Practice
- Try learngitbranching.js.org for interactive Git challenges.
- Explore GitHub Skills for guided GitHub learning paths.