Subsections of Getting Started with Git and GitHub

Git and GitHub Fundamentals

Overview of Git/GitHub

Working without Version Control:

Git and GitHub Fundamentals Git and GitHub Fundamentals

Working with Version Control:

Git and GitHub Fundamentals Git and GitHub Fundamentals

Git

  • Free and open source software
  • Distributed VCS
  • Accessible anywhere in the world
  • One of the most common version control systems available
  • Can also version control images, documents, etc.

Git and GitHub Fundamentals Git and GitHub Fundamentals

Short Glossary of Terms

SSH protocol – A method for secure remote login from one computer to another.

Repository – The folders of your projects that are set up for version control.

Fork – The process you use to request that someone reviews and approves your changes before they become final.

Working directory – A directory on your file system, including its files and subdirectories, that is associated with a git repository.

Introduction to GitHub

Background of Git:

  • Large software projects need a way to track and control source code updates
  • Linux needs automated source-version control
  • Key characteristics include:
    • Strong support for non-linear development
    • Distributed development
    • Compatibility with existing systems and protocols
    • Efficient handling of large projects
    • Cryptographic authentication of history
    • Pluggable merge strategies

Git Repository Model:

  • What is special about the Git Repository model?

    • Distributed VCS
    • Tracks source code
    • Coordinates among programmers
      • Tracks changes
      • Supports non-linear workflows
  • Created in 2005 by Linus Torvalds

    What is Git?

  • Git is a distributed VCS

    • Tracks changes to content
    • Provides a central point for collaboration
  • Git allows for centralized administration

    • Teams have controlled access scope
    • The main branch should always correspond to deployable code
  • IBM Cloud is built around open-source tools including Git repositories

GitHub

  • GitHub is an online hosting service for Git repositories
    • Hosted by a subsidiary of Microsoft
    • Offers free, professional, and enterprise accounts
    • Till 2022, it had over 100M repos
    • What is a Repository?
      • A data structure for storing documents including application source code
      • A repository can track and maintain version-control

GitLab

GitLab is:

  • A DevOps platform, delivered as a single application

  • Provides access to Git repositories

  • Provides source code management

    GitLab enables developers to:

  • Collaborate

  • Work from a local copy

  • Branch and merge code

  • Streamline testing and delivery with CI/CD

Using Git Commands and Managing GitHub Projects

GitHub Workflows with Branches and Git Commands

GitHub Branches

What are branches?

  • Branches store all files in GitHub
  • The master branch stores the deployable code
  • Create a new branch for planned changes

Using Git Commands and Managing GitHub Projects Using Git Commands and Managing GitHub Projects

Merging Branches:

  • Start with a common base
  • The code is branched while new features are developed
  • Both branches are undergoing changes
  • When the two streams of work are ready to merge, each branch’s code is identified as a tip and the two tips are merged into a third, combined branch

Using Git Commands and Managing GitHub Projects Using Git Commands and Managing GitHub Projects

What is a Pull Request?

  • A PR makes the proposed (committed) changes available for others to review and use

  • A pull can follow any commits, even if code is unfinished

  • PRs can target specific users

  • GitHub automatically makes a PR if you make a change on a branch you don’t own

  • Log files record the approval of the merge

    Merging into the Master/Main Branch

  • The master branch should be the only deployed code

  • Developers can change source files in a branch, but the changes are not released until

    • They are committed
    • A Pull command is issued
    • The code is reviewed and approved
    • The approved code is merged back into the master code

Cloning and Forking GitHub Projects

  • Powerful tools include forking and cloning a repository

  • Cloning creates a copy of a repository on your local machine

  • Cloned copies can sync between locations

  • Forking modifies or extends a project

    Remote Repositories:

  • Remote repos are stored elsewhere

  • Push, pull, and fetch data to share work

  • Origin refers to your fork

  • Upstream refers to the original work

Forking a Project

  • Forking
    • Takes a copy of a GitHub repository to use it as the base for a new project
    • Submit changes back to the original repository
  • Independently make changes to a project
    • Submit a PR to the original project owner
    • Owner decides whether to accept updates
  • Keep a copy of the license file
    • Often a legal requirement
    • Good practice

Syncing a Fork of a Project:

To keep a fork in sync with the original work from a local clone:

  • Create a local clone of the project

  • Configure Git to sync the fork

    • Open terminal and change to the directory containing the clone
    • To access the remote repository, type git remote -v
    • Type git remote add upstream <clone repo url>
    • To see the changes, type git remote -v

    Commands for Managing Forks:

    To grab upstream branches

git fetch upstream

To merge changes into the master branch

git merge upstream/master

Managing GitHub Projects

GitHub Developer:

A Developer communicates with others using these commands:

  • git-clone from the upstream to prime the local repository
  • git-pull and git-fetch from “origin” to keep-up-to-date with the upstream
  • git-push to shared repository, if you adopt CVS style shared repository workflow
  • git-format-patch to prepare email submission
  • git-send-email to send your email submission without corruption by your MUA (Mail User Agent)
  • git-request-pull to create a summary of changes for your upstream to pull

GitHub Integrator:

An integrator

  • Receives changes made by others

  • Reviews and responds to PRs

  • Publishes the result for others to use

    Integrators use the following commands:

  • git-am to apply patches emailed in from your contributors

  • git-pull to merge from your trusted lieutenants

  • git-format-patch to prepare and send suggested alternatives to contributors

  • git-revert to undo botched commits

  • git-push to publish the bleeding edge

GitHub Repository Administrator

A Repository Administrator sets up and maintains access to the repository by developers

  • git-daemon to allow anonymous download from repository
  • git-shell can be used as a restricted login shell for shared central repository users
  • git-http-backend provides a server-side implementation of Git-over-HTTP (Smart HTTP) allowing both fetch and push services
  • gitweb provides a web front-end to Git repositories, which can be set-up using the git-instaweb script