Simplified Guide to Git and GitHub

Sep 10, 2024

Git and GitHub Basics

Introduction

  • Many resources overcomplicate Git and GitHub.
  • This tutorial aims to simplify understanding by explaining concepts as if to a child.

Git vs GitHub

  • Git: A software installed on your computer for version control.
    • Pre-installed on Mac and Linux.
    • Requires download (Git Bash) on Windows.
  • GitHub: A website for hosting Git repositories.
    • Similar to Bitbucket and GitLab.

Understanding Git

  • Purpose: Acts like a memory card for your code.
    • Helps save progress similar to saving in video games.
  • Local Use: Git is used on your computer, not accessible by others unless shared.

Basic Git Commands

  1. Initializing Git: git init
    • Sets up an empty Git repository.
  2. Adding Changes: git add
    • git add [file]: Adds a specific file.
    • git add .: Adds all changes since the last save.
  3. Committing Changes: git commit -m "message"
    • Saves changes with a descriptive message.
  4. Viewing History: git log
    • Shows a log of all saved changes and their messages.
  5. Reverting to Previous Version: git checkout [commit-hash]
    • Allows reverting to a previous commit using its hash code.

Understanding GitHub

  • Purpose: Share code on the internet and collaborate with others.
  • Repository: Similar to a folder that holds your project.
    • Create a new repository via the GitHub profile.

Uploading to GitHub

  1. Connecting Local to Online: git remote add origin [URL]
    • Links your local repository to GitHub.
  2. Pushing Changes: git push
    • Uploads your local commits to GitHub.
  3. Pulling Changes: git pull origin master
    • Downloads changes from GitHub to your local machine.

Branching

  • Concept: Creates a separate version to make changes without affecting the main code.
    • git checkout -b [branch-name]: Create a new branch.
  • Merging: Combine changes from different branches.
    • Merge branches when changes are approved.

Collaboration

  • Pull Requests: Suggest changes for review before merging.
  • Branches in Collaboration: Others can create branches to propose changes.

Final Notes

  • Keeping Repositories Synced: Ensure local and GitHub repositories are consistent.
  • Rebasing: Advanced topic for future exploration.
  • GitHub Clout: Green squares indicate daily commits, sometimes pursued for appearance rather than impact.

Conclusion

  • The tutorial covers the basics necessary to start using Git and GitHub effectively.
  • Focus on practical usage without overcomplicating the process.