Essential Git Course Overview

Sep 19, 2024

Git Course Lecture Notes

Introduction to Git

  • Purpose of Git: Version control and collaboration.
  • Usage Context: Applicable for various applications: mobile, web, enterprise.
  • Focus: Commands and practical learning.
  • Course Structure:
    • Understanding Git basics
    • Setting up Git and GitHub accounts
    • Creating repositories
    • Committing and pushing code
    • Branch management

Understanding Version Control

  • Version Control Definition: Managing changes to a project over time.
  • Typical Workflow:
    • Creating different versions (or updates) of a project.
    • Importance of saving previous versions to recover from errors.

Types of Version Control Systems

  1. Local Version Control: Only available on the developer's machine.
    • Issues with collaboration and data loss if the machine fails.
  2. Centralized Version Control (CVCS): Rely on a central server for version control.
    • Allows access to a shared repository but risks data loss if the server fails.
  3. Distributed Version Control System (DVCS): Each developer has a complete local copy of the repository.
    • Enables working offline and greater collaboration.

Git Overview

  • Git: A distributed version control system.
  • Remote Repositories: Examples include GitHub, GitLab, Bitbucket.
  • Core Commands: git init, git add, git commit, git push, git pull, git branch, etc.

Setting Up Git

  • Installation: Check for Git installation using git version command.
  • Configuration: Set user name and email for commits.

Creating Your First Project

  • Initializing a Repository: Use git init to create a local repository.
  • Staging Files: Stage files using git add <filename>.
  • Committing Changes: Use git commit -m "message" to save changes with a message.

Branching in Git

  • Branches: Used to work on features independently without affecting the main codebase.
  • Creating a Branch: Use git branch <branch-name> or git checkout -b <branch-name>.
  • Switching Branches: Use git checkout <branch-name> or git switch <branch-name>.
  • Merging Branches: Combine changes from one branch into another using git merge <branch-name>.

Viewing Branches

  • Checking Current Branch: Use git branch to list branches.
  • Visualizing History: Use git log --graph to visualize commits in a branching structure.

Remote Repositories and Collaboration

  • Pushing Changes: Use git push origin <branch-name> to push local changes to the remote repository.
  • Pulling Changes: Use git pull origin <branch-name> to fetch and merge changes from the remote.
  • Managing Collaborations: Ensure to pull changes before merging to avoid conflicts.

Tags in Git

  • Tagging: Used to mark specific points in the repository’s history as important (like releases).
  • Creating Tags: Use git tag -a <tag-name> -m "message" to create an annotated tag.
  • Pushing Tags: Tags need to be pushed separately using git push origin <tag-name>.

Best Practices

  • Commit Often: Frequent commits help maintain a clear history.
  • Meaningful Commit Messages: Use informative messages to improve readability of commit history.
  • Pull Before Pushing: Always pull changes from the remote before pushing your own to avoid conflicts.