DevOps 15-20 Min Read Beginner to Expert

Git & GitHub Masterclass: A Developer's Survival Guide to Version Control

Git & GitHub Masterclass: A Developer's Survival Guide to Version Control

Introduction: The Day I Lost 3 Days of Work

In my early days, I used to copy-paste my project folder to create a backup. One day, I accidentally overwrote a file with an old version. I lost 3 days of work. I wanted to cry. That's when a senior developer introduced me to Git. It changed my life. In this guide, I'm going to teach you the only 5 Git commands you need to get started.

What is Git and GitHub?

Git is a version control system. It's a tool that tracks changes in your files. Think of it as a time machine for your code. GitHub is a cloud platform where you can host your Git repositories. It's like a social network for developers, but it's also where your code lives.

Core Concept: The Three Stages

Step-by-Step Execution

  1. Install Git: Download from git-scm.com and install it.
  2. Initialize a Repository: Open your terminal, navigate to your project folder, and run `git init`.
  3. Stage Changes: Run `git add .` to stage all files.
  4. Commit: Run `git commit -m "Initial commit"`. This saves a snapshot.
  5. Connect to GitHub: Create a new repo on GitHub. Copy the remote URL. Run `git remote add origin `.
  6. Push: Run `git push -u origin main` to upload your code to GitHub.

What About Branches?

Branches are a way to work on new features without breaking the main code. You can create a branch using `git checkout -b new-feature`. Once you're done, you can merge it back into the main branch.

Common Mistakes Beginners Make

Practical Exercise (Don't Skip This)

Create a new folder, add a simple text file, and initialize a Git repository. Commit the file. Then, create a new branch, make a change, and commit it. Finally, merge it back to the main branch. If you get stuck, email me at digisoneglobal@gmail.com.

Frequently Asked Questions

Q: Is GitHub the only platform?
A: No. GitLab and Bitbucket are popular alternatives. However, GitHub is the industry standard for open-source.

Q: Do I need to know the command line?
A: It's highly recommended. You can use a GUI tool like GitHub Desktop, but learning the CLI will make you a better developer.

Tools & Resources Mentioned

Conclusion & Next Steps

Git is a skill that pays for itself tenfold. Once you get comfortable with it, you'll never go back to manual backups. Next, we'll dive into how to collaborate with others on GitHub.

Back to Masterclasses