Complete Git and GitHub Tutorial Notes

Jul 24, 2024

Complete Git and GitHub Tutorial Notes

Introduction

  • Overview of Git and GitHub from scratch.
  • Covers beginner concepts as well as intermediate ones.

What is Git and GitHub?

  • Git: A version control system for tracking changes in code.
  • GitHub: A platform for hosting Git repositories online for collaboration.

Use Cases for Git

  • Collaborating on projects with multiple contributors
  • Going back to a previous state of the codebase (e.g., reversing changes that caused errors).

Key Concepts

  • Repository: A folder where changes are saved.
  • Version Control: System that records changes to files over time.

The Git Workflow

  1. Install Git: Download from gitscm.com for macOS, Windows, or Linux.
  2. Set Up a Project:
    • Create a project folder using command mkdir project.
    • cd project to change into the project directory.
    • Initialize Git repository with git init.

Tracking Changes

  • To check status of files: git status
  • To add a file: git add filename
  • To commit changes: git commit -m "commit message"

Basic Git Commands

  • git init: Initializes a new Git repository.
  • git add: Stages changes for the next commit.
  • git commit: Records changes with a message.
  • git status: Shows the status of working directory and staging area.
  • git log: Views the commit history.
  • git remote: Links to a remote repository.

Branching in Git

  • Branches allow different features and bug fixes to be developed in isolation.
  • Main Branch: The primary branch where the code is stable.
  • Creating Branches: Use git branch branch-name and then git checkout branch-name.

Pull Requests

  • A way to propose changes to a repository.
  • A pull request notifies the repository maintainers of your changes and asks for them to be merged.

Merging Changes

  • Once changes are finalized, merge into the main branch using git merge branch-name.
  • Do not commit directly to the main branch.

Dealing with Conflicts

  • Conflicts occur when two changes collide on the same line.
  • Git prompts the user to resolve any conflicts before merging.

Fetching and Updating

  • To keep your fork of a project up-to-date with the upstream repository, use git fetch and git merge commands.

Conclusion

  • Practical experience is important for mastering Git and GitHub.
  • Encourage to experiment with creating branches, making commits, resolving conflicts, and creating pull requests.

Call to Action

  • Links to Git cheat sheets and other resources will be provided.
  • Follow along with practical exercises in a community classroom setting.