Git

Hero Shot

Summary

Introduction to Git

Git is a version control system designed to help track changes in files and facilitate collaboration. It provides:

  1. History: Keeps track of changes made to files.
  1. Collaboration: Enables teams to work together effectively.

Ways to Use Git

  1. Command Line: The most powerful and direct way to use Git.
  1. Integrated Development Environment (IDE): Many IDEs have built-in Git support (e.g., VSCode).
  1. Graphical User Interface (GUI): Tools like GitKraken simplify Git visually.

Work Process Detail

  • Git Tutorial


How to Download and Install Git Bash

Git Bash is a command-line tool for Windows that allows you to use Git commands and Linux-like features. Follow these steps to download and install Git Bash:

  • 1. Download Git
    1. Go to the official Git website: git-scm.com.
    1. Click on the Download button. The site will automatically detect your operating system (Windows, macOS, or Linux).
  • 2. Install Git on Windows
    1. Once the file is downloaded, locate it (e.g., Git-x.x.x-x64.exe) and double-click to open the installer.
    1. Follow the installation wizard steps:
      • Select Destination Location: Choose where to install Git or leave it as the default.
      • Select Components: Ensure "Git Bash Here" and "Git GUI Here" are selected.
      • Default Editor: Choose an editor for Git (e.g., VSCode or Nano).
      • Adjust PATH Environment: Select "Use Git from the command line and also from third-party software" (recommended).
      • HTTPS Settings: Leave the default option (Use OpenSSL).
      • Line Ending Conversions: Use the default option ("Checkout Windows-style, commit Unix-style line endings").
      • Terminal Emulator: Select "Use MinTTY" (default terminal for Git Bash).
      • Continue with the default options for the remaining steps unless you need custom configurations.
    1. Click Install and wait for the installation to complete.
  • 3. Launch Git Bash
    1. After the installation is complete, click Finish.
    1. Open Git Bash:
      • Use the Start Menu to search for "Git Bash."
      • Alternatively, right-click anywhere on your desktop or in a folder, and select "Git Bash Here."
  • 4. Verify Installation
    1. Open Git Bash and type:

      This will display the installed Git version, confirming a successful installation.
      git --version
      

Setting Up Git

Configure Git for the First Time:

  1. Set your name:
    git config --global user.name "Your Name"
    
  1. Set your email:
    git config --global user.email "your.email@example.com"
    
  1. Configure a default editor (e.g., VSCode):
    git config --global core.editor "code --wait"
    
  1. Enable line endings for compatibility:
    git config --global core.autocrlf true
    

Check Git Configuration:

  • View Git settings:
    git config --list
    
  • For help:
    git --help
    git -h
    

Basic Git Commands and Workflow

Initialize a Repository

  1. Create and navigate to a directory:
    mkdir project_name
    cd project_name
    
  1. Initialize Git in the directory:
    git init
    

Workflow Steps

  1. Edit files as needed.
  1. Check the current status:
    git status
    
  1. Add files to the staging area:

    To add all changes:
    git add file_name
    
    git add .
    
  1. Commit the changes:
    git commit -m "Your commit message"
    

Understanding Git Workflow

Credit: https://www.youtube.com/@programmingwithmosh
  1. Files: The working directory contains files you are editing.
  1. Index: Staging area where changes are prepared for a commit.
  1. Repository: Where the final snapshot of your project is stored after a commit.

Removing Files in Git

  1. Delete a file from your working directory:
    rm file_name
    
  1. Stage the removal:
    git add file_name
    
  1. Commit the removal:
    git commit -m "Removed file_name"
    
  1. Alternatively, remove and stage in one step:
    git rm file_name
    

Visual Representation of Commit Sizes

  • Small, incremental commits are preferred over large commits. They make tracking and debugging easier.

Learning Outcome

Learning Git workflow is super impotent for team work and project development, and knowing how to use it will help the maker community to level up their development.

Digital Files