📁

Comprehensive Git and GitHub Guide

Oct 23, 2024

Git and GitHub Tutorial

Introduction

  • Tutorial on Git and GitHub usage
  • Covers basic to intermediate Git concepts: repositories, GitHub, branching, merging, forking
  • Presented by Gwen from Faraday Academy

What is Git?

  • Free and open-source version control system
  • Tracks code changes overtime
  • Widely used by developers

Version Control

  • Helps programmers track code changes
  • Allows reverting to previous versions
  • Useful for bug tracking and history review

Key Terminology

  • Directory: Folder on your computer
  • Terminal/Command Line: Text-based interface for running commands
  • CLI: Command Line Interface
  • CD (Change Directory): Command to navigate between folders
  • Code Editor: Application to write code (e.g., Visual Studio Code)
  • Repository: Project or code storage area
  • GitHub: Online platform to host Git repositories

Basic Git Commands

  • Clone: Copy repository from GitHub to local machine
  • Add: Stage changes for commit
  • Commit: Save changes to local repository
  • Push: Upload local changes to remote repository
  • Pull: Download changes from remote repository

Setting Up Git

  • Check if Git is installed by running git --version
  • Install Git if necessary
  • SSH keys setup for GitHub authentication

Creating and Managing Repositories

  • Create new repositories on GitHub
  • Initialize local repositories with git init
  • Connect local repos to GitHub with git remote add origin <URL>

Local Workflow

  1. Write code in a code editor
  2. Use git add to stage changes
  3. Use git commit to save changes
  4. Use git push to upload changes to GitHub

Git Branching

  • Branch: Parallel version of a repository
  • Master branch: Default branch
  • Create a new branch with git checkout -b <branch-name>
  • Switch between branches with git checkout <branch-name>

Merging and Pull Requests

  • Merge: Combine changes from different branches
  • Pull Request (PR): Request to merge changes into another branch
  • Review and resolve comments on PRs

Handling Merge Conflicts

  • Occur when changes are conflicting
  • Resolve conflicts manually in the code editor

Undoing Changes

  • Unstage changes with git reset <file>
  • Undo commits with git reset HEAD~1
  • Hard reset with git reset --hard <commit-hash> to discard changes

Forking Repositories

  • Create a copy of a repository on GitHub
  • Useful for contributing to others’ projects
  • Make changes and submit pull requests back to original repo

Conclusion

  • Encouragement to practice using Git
  • Invitation to subscribe to Faraday Academy
  • Feedback request for the tutorial