Welcome to the Git Basics Workshop! This repository contains exercises to help you learn essential Git commands.
- Git installed on your computer
- A GitHub account
- A text editor
- Fork this repository by clicking the "Fork" button at the top right of this page
- Clone your forked repository in your computer's terminal:
git clone https://github.com/<github username>/<forked repo name>
cd <forked repo name>
mkdir git-workshop
cd git-workshop
- Create a new file called
introduction.txt
(touch introduction.txt
in your terminal or create a new file in your file explorer) - Add your name and one fun fact about yourself
- Stage the file:
git add introduction.txt
- Commit the change:
git status # Check what's staged
git commit -m "Add personal introduction"
- Create and switch to a new branch:
git checkout -b feature/add-hobby
- Create a file called
hobbies.txt
and list your hobbies - Stage and commit your changes
- Switch back to main:
git checkout main
- Merge your feature branch into main:
git merge feature/add-hobby
- Resolve any conflicts if they occur
- Create a new branch called
feature/favorite-foods
- Add a file
favorite-foods.txt
with your top 3 favorite foods - Stage and commit your changes
- Push your branch to GitHub:
git push origin feature/favorite-foods
- Create a Pull Request on GitHub
- Pull the latest changes from the main branch:
git checkout main
git pull origin main
# Repository Setup
git clone <url> # Clone a repository
git init # Initialize a new repository
# Basic Commands
git status # Check repository status
git add <file> # Stage changes
git commit -m "message" # Commit changes
git push # Push changes to remote
git pull # Pull changes from remote
# Branching
git branch # List branches
git checkout <branch> # Switch branches
git checkout -b <name> # Create and switch to new branch
git merge <branch> # Merge branches
# History
git log # View commit history
git diff # View changes
- If you make a mistake in your last commit message:
git commit --amend -m "New message"
- If you need to undo staged changes:
git reset HEAD <file>
- If you need to discard local changes:
git checkout -- <file>
- Try creating multiple branches and merging them
- Practice resolving merge conflicts
- Experiment with
git revert
to undo commits - Create a
.gitignore
file and test it
If you get stuck, try these steps:
- Check
git status
to see what's happening - Look at the error message carefully
- Ask a workshop mentor for help
- Google the error message (a very real developer skill!)