Introduction to Git and GitHub eBook

repository·main·Indexed 22 days ago

https://github.com/bobbyiliev/introduction-to-git-and-github-ebook

An open-source educational resource providing a comprehensive guide to Git and GitHub for developers, DevOps engineers, and SysOps professionals. The guide covers version control fundamentals, including installation, basic shell commands, Git configuration, local and remote repositories, and workflows such as branching, merging, and using the GitHub CLI.

Tokens
24.4K
Snippets
126
Records
172
Agent score
73%

What's inside introduction-to-git-and-github-ebook

  1. Overview of eBook Chapters

    main

    The eBook is organized into several topical chapters covering the full spectrum of Git and GitHub usage. Key topics include:

    • Setup: Installing Git, Git Configuration, and SSH Keys.
    • Basic Workflow: Initializing projects, git status, git add, git commit, git diff, and git log.
    • Remote Operations: git push, git pull, git clone, and Forking.
    • Branching & Merging: Git Branches, Git Merge, Git Rebase, and Git Switch.
    • Advanced/Utility: Git Stash, Git Alias, Gitignore, Pull Requests, and GitHub CLI.
    • Reference: GitHub Markdown Cheatsheet and a Git Command Cheat Sheet.
  2. What is a Version Control System (VCS)?

    main

    A Version Control System (VCS), also known as a Source Code Manager (SCM) or Revision Control System (RCS), is a tool that maintains control over changes in files. If issues occur, it allows you to "go back in time," compare changes, and revert to a functional state of your source code.

    Common examples of VCS include:

    • Git (extremely popular)
    • SVN
    • Mercurial

    All these systems are free and open-source.

  3. What is Git and why use it?

    main

    Git is an open-source distributed version control system designed for tracking changes in source code. It is used to coordinate work among developers by allowing them to track code changes, create branches for new ideas, and collaborate via platforms like GitHub or GitLab.

    Key goals of Git include:

    • Speed: Efficient handling of repository operations.
    • Data Integrity: Ensuring the history of changes is preserved and secure.
    • Distributed Workflows: Supporting workflows where every developer has a local copy of the repository.
  4. What is Git Rebase and how does it differ from Merge

    main

    Concept

    Rebase updates a branch by applying its commits on top of another branch. This effectively moves the entire base of your branch to a new starting point (the tip of the target branch), creating a linear history.

    Merge integrates changes from one branch into another by creating a new 'merge commit' that preserves the history of both branches at their original bases.

    Use Rebase when you want a clean, linear project history. Use Merge when you want to preserve the exact historical context of when branches were joined.

  5. Understand git diff output format

    main

    When running git diff, the output follows a specific structure to indicate changes:

    • diff --git a/filename b/filename: Indicates which file is being compared.
    • @@ -line,count +line,count @@: Shows the line numbers affected by the change.
    • +: A line starting with a plus sign indicates a new line that was added.
    • -: A line starting with a minus sign indicates a line that was removed.
    diff --git a/README.md b/README.md
    index 9366068..2b14655 100644
    --- a/README.md
    +++ b/README.md
    @@ -1 +1,2 @@
     # Projeto Demo
    +Git é incrível
  6. How Distributed Version Control works with Git and GitHub

    main

    With distributed version control systems like Git, your source code is stored in two primary locations:

    1. Remote Repository: A hosted version of your project (e.g., on GitHub).
    2. Local Repository: A copy of the project stored on your personal computer.

    This dual-storage model provides a safety net: if your local machine fails, your changes remain secure in the remote repository on GitHub.

  7. Understand Git configuration storage: `~/.gitconfig` and `.git/config`

    main

    Git stores configuration settings in different locations depending on their scope:

    1. Global Configuration: Stored in the ~/.gitconfig file in your home directory. These settings apply to all repositories for your user. You can view this file using cat ~/.gitconfig.
    2. Repository Configuration: Stored in the .git/config file within the specific project's .git directory. These settings apply only to that specific project and override global settings.

    Every Git-initialized project contains a .git directory that holds the project's history and local configuration.

    # View global config file content
    cat ~/.gitconfig
    
    # List contents of the local .git directory
    ls .git
  8. What are Git branches and why use them?

    main
    A Git branch is a lightweight, movable pointer to a specific commit. Conceptually, branches allow you to work on new features or bug fixes in isolation without affecting the main branch. This enables multiple developers to work on different parts of a project simultaneously without interfering with each other's code. Once a feature is complete and tested on its own branch, it can be merged back into the main branch.
  9. What are Git branches?

    main

    A Git branch is a lightweight, movable pointer to a specific commit.

    Branches allow you to work on new features or bug fixes in isolation without affecting the main branch. This enables multiple developers to work on different parts of the same project simultaneously without interference. Once work in a separate branch is tested and complete, it can be merged back into the main branch.