Git and GitHub for Beginners - Course Notes

Jul 9, 2024

Git and GitHub for Beginners by Hest Chowy

Introduction

  • Instructor: Hest Chowy
  • Focus: Essentials of Version Control using Git
  • Goal: Manage projects efficiently using Git, GitHub, and other services.

Series Overview

  • Master Git from both theoretical and practical perspectives.
  • Exploration of associated services like GitHub and Bitbucket.
  • Not just memorizing commands but understanding the workflow of Git.
  • Target Audience: Engineers entering the software engineering domain.

Why Version Control?

  • Collaboration among multiple engineers.
  • Provides checkpoints (similar to game save points) - facilitates rollback to working state if something breaks.
  • Known as Version Control System (VCS) or Versioning System.

Concepts and Tools

  • Git: A terminal-based tool, recommended over GUI for better industry practice.
  • Terminal: Current recommendation is Warp for Mac & Linux; Windows version coming soon.
  • IDE: Visual Studio Code recommended for editing (language-independent).
  • Preparing notes in classical pen-and-paper style.

Git Setup Instructions

  • Software Needed: Git and Visual Studio Code.
  • Terminal emphasis: Command-line familiarity is vital for Git workflows.
  • Installation & Configuration: Download Git from official website, open and install with default settings.
  • Git version check with git --version.

Initial Commands and Setup

  • Folder Setup: Create project folders and navigate using terminal commands (mkdir, cd, etc.).
  • Init Command: git init to initialize Git repository in a folder.
  • Status Check: git status to check the repository state.
  • Hidden Git Folder: .git folder created to track changes.

Commit Workflow

  • Staging Area: Files must be added to the staging area using git add <filename> or git add . before committing.
  • Commit: git commit -m <message> to save changes in local repo.
  • View Logs: git log and git log --oneline to view commit history.

Branching

  • Branches: Work on separate parts of a project without disturbing the main project state.
  • Create Branch: git branch <branchname> and switch with git checkout <branchname> or git switch <branchname>.
  • Merge Branches: git merge <branchname> merges changes into the current branch.
  • Conflict Resolution: Manual adjustment of files if changes conflict.
  • Rebase: Integrate changes from one branch into another, usually to streamline commits.

GitHub Integration

  • Account Setup: Create a GitHub account.
  • SSH Keys: Generate SSH keys and add to GitHub account for secure connection.
  • Repository Creation: Create repositories from GitHub UI and connect local Git repo using given commands.
  • Push Commands: git push -u origin main sets upstream branch, later pushes require only git push.

Pull Requests & Collaboration

  • Fork Repositories: Create a personal copy of someone else's project to work on changes.
  • Pull Requests: Submit changes to the original project via PR for review and potential merging.
  • Code Review: Maintainers review and request changes if needed.
  • Merge PR: Once approved, changes are merged and reflected in the original repository.

Open-Source Contribution

  • Steps: Talk to maintainers, open an issue, get it assigned, add value, submit PR, iterate based on feedback, and celebrate the contribution.
  • Communication: Essential to avoid overlapping work and ensure contributions are valuable.
  • Documentation: Read more about how to contribute effectively and respectfully to open-source projects.

Conclusion

  • Usage: Use Git daily to get comfortable and improve understanding.
  • Encouragement: Share experiences, contribute to open-source, and practice ethical programming.
  • Future Learning: Continue with advanced Git features and explore related tools and services.