Git & GitHub
Version control basics
Learning to use Git and GitHub is a superpower that will change the way you build projects and collaborate with others. Let's explore how it can make your coding life easier and more organized.
What is Git?
Git is a version control system. Think of it as a super-smart save button for your code. It tracks every change you make to your files. So, you can always look back at old versions or even undo mistakes easily.
- You can see who changed what and when.
- You can experiment with new features without breaking your main project.
- It helps multiple people work on the same project without stepping on each other's toes.
Why you need Git
Imagine you're writing a big Python program. You add a new feature, and suddenly everything breaks. Without Git, you'd have to manually try to remember all the changes you made to fix it.
With Git, you just go back to a previous working version. It's like a time machine for your code! This saves a lot of headaches and makes you a more confident developer.
# Initialize a new Git repository
git init
# Check the status of your files
git status
# Add files to the staging area
git add .
# "Save" your changes with a message
git commit -m "Initial commit: Added basic structure"What we'll cover
We will learn the essential Git commands you'll use every day. We'll start with setting up Git locally and then move to publishing your projects on GitHub.
- Initializing a new Git repository.
- Making commits and understanding commit messages.
- Pushing your code to GitHub.
- Pulling changes from GitHub.
- Branching and merging for features.
# example.py
def greet(name):
return f"Hello, {name}!"
if __name__ == "__main__":
print(greet("World"))
# Imagine we make changes here later
# print(greet("Git User"))