Welcome to the Git & GitHub Workshop! This repository is designed to help beginners learn essential Git commands and GitHub workflows through hands-on practice.
This workshop will teach you:
- Basic Git setup and configuration
- Creating and managing branches
- Making commits and tracking changes
- Working with files in Git
- Merging branches and resolving conflicts
- Collaborating with remote repositories
Before starting, make sure you have:
- Git installed on your computer (Download Git)
- A GitHub account (Sign up for GitHub)
- A text editor (VS Code, Sublime Text, or any editor you prefer)
- Fork this repository: Click the "Fork" button at the top right of this page
- Clone your fork: Replace
YOUR_USERNAME
with your GitHub usernamegit clone https://github.com/YOUR_USERNAME/Github-Workshop.git cd Github-Workshop
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Goal: Learn basic Git commands and create your first commit
-
Check repository status:
git status
-
Create a new file with your information:
echo -e "Name: Your Name \nFavorite Programming Language: Your Language" > student-info.md
-
Stage and commit your changes:
git add student-info.txt git commit -m "Add my student information"
-
View commit history:
git log --oneline
Goal: Create and work with different branches
-
Create and switch to a new branch:
git checkout -b feature/my-project
-
Create a simple project file:
mkdir my-project echo -e "# My First Project\n\nThis is a project I'm working on during the Github workshop." > my-project/README.md
-
Commit your project:
git add my-project/ git commit -m "Add my first project"
-
Switch back to main branch:
git checkout main
-
List all branches:
git branch -a
Goal: Practice adding, modifying, and removing files
-
Switch to your feature branch:
git checkout feature/my-project
-
Add a new file to your project:
echo "print('Hello, Git Workshop!')" > my-project/hello.py
-
Modify an existing file:
echo -e "\n## Features\n- Learning Git\n- Having fun!" >> my-project/README.md
-
Stage all changes:
git add .
-
Commit your changes:
git commit -m "Add hello.py and update README with features"
Goal: Learn how to merge branches
-
Switch to main branch:
git checkout main
-
Merge your feature branch:
git merge feature/my-project
-
Delete the feature branch (optional):
git branch -d feature/my-project
-
View updated log:
git log --oneline --graph
Goal: Learn to push changes to GitHub
-
Push your changes to GitHub:
git push origin main
-
Create a new branch for collaboration:
git checkout -b feature/collaboration
-
Add a collaboration file:
echo "This file was created to practice collaboration!" > collaboration.md git add collaboration.md git commit -m "Add collaboration file"
-
Push the new branch:
git push origin feature/collaboration
Goal: Learn to resolve merge conflicts
-
Create two conflicting branches:
git checkout main git checkout -b branch-a echo "This is version A" > conflict-file.txt git add conflict-file.txt git commit -m "Add version A" git checkout main git checkout -b branch-b echo "This is version B" > conflict-file.txt git add conflict-file.txt git commit -m "Add version B"
-
Merge and resolve conflict:
git checkout main git merge branch-a git merge branch-b # This will create a conflict!
-
Resolve the conflict by editing the file:
- Open
conflict-file.txt
in your editor - Choose which version to keep or combine both
- Remove the conflict markers (
<<<<<<<
,=======
,>>>>>>>
)
- Open
-
Complete the merge:
git add conflict-file.txt git commit -m "Resolve merge conflict between branch-a and branch-b"
Practice using:
git checkout -- filename
(undo unstaged changes)git reset HEAD filename
(unstage files)git revert commit-hash
(revert a commit)
Learn to clean up commit history:
git rebase -i HEAD~3
Command | Description |
---|---|
git status |
Check the status of your working directory |
git add <file> |
Stage a file for commit |
git add . |
Stage all changes |
git commit -m "message" |
Commit staged changes |
git push origin <branch> |
Push branch to remote |
git pull origin <branch> |
Pull changes from remote |
git checkout <branch> |
Switch to a branch |
git checkout -b <branch> |
Create and switch to a new branch |
git merge <branch> |
Merge a branch into current branch |
git branch |
List local branches |
git branch -a |
List all branches (local and remote) |
git log --oneline |
View commit history |
git diff |
View unstaged changes |
After completing all exercises, you should have:
- Configured Git with your name and email
- Created and committed a student info file
- Created and worked with feature branches
- Added, modified, and committed files
- Merged branches successfully
- Pushed changes to your GitHub repository
- Resolved at least one merge conflict
- Created a simple project structure
If you get stuck:
- Check the Git documentation:
git help <command>
- Ask your instructor or classmates
- Search for solutions online (Stack Overflow is your friend!)
- Use
git status
to understand your current situation
After completing this workshop:
- Explore more Git features like stashing, rebasing, and tagging
- Learn about GitHub features like Issues, Pull Requests, and Actions
- Practice collaborating on real projects
- Contribute to open-source projects
Happy learning! π Remember, the best way to learn Git is by practicing regularly.