Essentials On Azure DevOps Services and GitHub Book 5
Essentials On Azure DevOps Services and GitHub Book 5
and GitHub
Conditions and Terms of Use
Microsoft Confidential
http://www.microsoft.com/en-us/legal/intellectualproperty/Permissions/default.aspx
How to View This Presentation
• Switch to the Notes Page view:
o Click View on the ribbon, and select Notes Page
o Use the Page Up or Page Down keys to navigate
o Zoom in or out as needed
Microsoft Confidential
Introduction and Logistics
• Your trainer
• You:
o Your role
o Your company
o Your experience in this technology area
o Your goals for this workshop
Microsoft Confidential
Module 3: GitHub
Repositories
Module Overview
Microsoft Confidential
Overview
• Git Overview
• Create and manage repositories
• Collaborate by using GitHub
Microsoft Confidential
Module 3: GitHub Repositories
Microsoft Confidential
Overview
• Git
• Benefits of Git
• Git Basics
• Install and Set Up Git
Microsoft Confidential
Microsoft Confidential
Git
• Git is the most used version control system today and is quickly becoming the standard for version
control
• Git is a distributed version control system, meaning your local copy of code is a complete version
control repository. These fully-functional local repositories make it is easy to work offline or remotely
• You commit your work locally, and then sync your copy of the repository with the copy on the server
• This paradigm differs from centralized version control where clients must synchronize code with a server
before creating new versions of code
• Nearly every development environment has Git support and Git command line tools run on every major
operating system.
Microsoft Confidential 9
Benefits of Git
• Simultaneous development
• Faster releases
• Built-in integration
• Strong community support
• Pull Requests
• Branch Policies
Microsoft Confidential 10
Git Basics - Commit
• Every time you save your work, Git creates a commit
• A commit is a snapshot of all your files at a point in time
• If a file has not changed from one commit to the next, Git uses the previously stored file. This
design differs from other systems which store an initial version of a file and keep a record of
deltas over time
• Commits create links to other commits, forming a graph of your development history
• You can revert your code to a previous commit, inspect how files changed from one commit to
the next, and review information such as where and when changes were made
• Commits are identified in Git by a unique cryptographic hash of the contents of the commit.
Because everything is hashed, it is impossible to make changes, lose information, or corrupt
files without Git detecting it
Microsoft Confidential 11
Git Basics - Branches
• Git provides tools for isolating changes and later merging them back together
• Branches, which are lightweight pointers to work in progress, manage this separation
• Once your work created in a branch is finished, merge it back into your team’s main branch
• Customizable default branch name for Git
Microsoft Confidential 12
Git Basics – Files and Commits
• Files in Git are in one of three states: modified, staged,
or committed
• When you first modify a file, the changes exist only in
your working directory. They are not yet part of a commit
or your development history
• First stage the changed files you want to include in your
commit
• Then commit them with a message describing what
changed
• Staging lets you pick which file changes to save in a
commit
• When you reduce the scope of your commits, it’s easier
to review the commit history to find specific file changes
Microsoft Confidential 13
Git Basics - History
• Centralized systems store a separate history for each file in a repository.
• Git stores history as a graph of snapshots of the entire repository. These snapshots—which are
called commits in Git—can have multiple parents, creating a history that looks like a graph instead
of a straight line.
Microsoft Confidential 14
Git Basics - Repositories
• A Git repository, or repo, is a folder that
you've told Git to help you track file changes
in.
• You can have any number of repos on your
computer, each stored in their own folder.
• Each Git repo is independent, so changes
saved in one Git repo don't affect the
contents of another.
• A Git repo contains every version of every
file saved in the repo.
• Most teams will use a central repo hosted on
a server everyone can access to coordinate
their changes.
Microsoft Confidential
Microsoft Confidential
Install and Set Up Git
• Windows
o Download and install Git for Windows
o Once installed, you’ll be able to use Git from the command prompt or PowerShell
o Update Git for Windows by downloading a new version of the installer, which will update Git for Windows in place
and keep all of your settings.
• macOS
o macOS 10.9 (Mavericks) or higher will install Git the first time you try to run Git from the Terminal
o We recommend installing Git through Homebrew and using the Homebrew tools to keep Git up-to-date.
• Linux
o Use your Linux distribution’s package management system to install and update Git.
o E.g. on Ubuntu:
> sudo apt-get install git
• It’s important to keep Git up to date, just like all the other software on your machine. Updates protect you
from security vulnerabilities, fix bugs, and give you access to new features.
Microsoft Confidential 16
Demo 1: Git Overview
Microsoft Confidential
17 Microsoft Confidential
Lesson Knowledge Check
1. What is Git?
2. What is a Commit?
Microsoft Confidential
Lesson Summary
• In this lesson, you learned about:
o Git
o Benefits of Git
o Git Basics
o Install and Set Up Git
Microsoft Confidential
Module 3: GitHub Repositories
Microsoft Confidential
Overview
• About repositories
• Creating a new repository
• Managing repositories
Microsoft Confidential
Microsoft Confidential
About repositories
• A repository contains all of your project's files and each file's revision history
• Discuss and manage your project's work within the repository
• Own repositories individually or share ownership of repositories with other people in an organization
• Restrict who has access to a repository by choosing the repository's visibility
o Public repositories are accessible to everyone on the internet
o Private repositories are only accessible to you, people you explicitly share access with, and, for organization
repositories, certain organization members
Microsoft Confidential 23
Creating a new repository
• New repository
• Create a repository with the directory structure and files of an existing repository
Microsoft Confidential 24
Manage repositories
• Duplicating a repository
o Maintain a mirror of a repository without forking it using a special clone command, then mirror-push to the new
repository
• Cloning a repository
o Clone your existing repository or clone another person's existing repository to contribute to a project
Microsoft Confidential 25
Manage repositories (continued)
• Renaming a repository
o Organization owner or anyone with admin permissions can rename a repository
o All existing information, except for project site URLs, is automatically redirected to the new name, including:
▪ Issues
▪ Wikis
▪ Stars
▪ Followers
• Transferring a repository
o Transfer repositories to other users or organization accounts
o When you transfer a repository, its issues, pull requests, wiki, stars, and watchers are also transferred.
Microsoft Confidential 26
Manage repositories (continued)
• Deleting a repository
o Delete any repository or fork if you're either an organization owner or have admin permissions for the repository or
fork
Microsoft Confidential 27
Demo 2: Create and manage
repositories
Microsoft Confidential
28 Microsoft Confidential
Lesson Knowledge Check
1. True/False: You can restrict who has access to a repository by choosing the repository's visibility.
2. True/False: Deleted repositories can be restored within 180 days.
Microsoft Confidential
Lesson Summary
• In this lesson, you learned about:
o Repositories
o Creating a new repository
o Managing repositories
Microsoft Confidential
Module 3: GitHub Repositories
Microsoft Confidential
Overview
• Creating and editing commits
• Viewing and comparing commits
• Branches and merges
• Fetch
• Push
• Pull
• Protected branches
• Working with forks
• Collaborative development models
• Pull requests
• Status checks
Microsoft Confidential
Microsoft Confidential
Creating and editing commits
• Save small groups of meaningful changes as commits
• Git assigns each commit a unique ID, called a SHA or hash, that identifies:
o The specific changes
o When the changes were made
o Who created the changes
Microsoft Confidential 34
Viewing and comparing commits
• View the commit history of a repository by:
o Navigating directly to the commits page of a repository
o Clicking on a file, then clicking History, to get to the commit history for a specific file
• Compare two arbitrary commits in your repository or its forks on GitHub in a two-dot diff comparison
Microsoft Confidential 35
Branches and merges
• Use a branch to isolate development work without affecting other branches in the repository
• Each repository has one default branch, and can have multiple other branches
• Merge a branch into another branch using a pull request
Microsoft Confidential 36
Fetch
• Download changes to your local branch from the remote through fetch.
• Fetch asks the remote repo for all commits and new branches that others have pushed but you don't have
and downloads them into your repo, creating local branches as needed.
• Fetch does not merge any changes into your local branches, it only downloads the new commits for your
review.
• To help keep your branches list clean and up to date, configure Git to prune remote branches during fetch.
• When to fetch
o When you want to preview the changes from your team before you integrate them into your work
o Before you get a copy of a branch that someone on your team has published
• Merge takes the commits retrieved from fetch and tries to add them to your local branch.
Microsoft Confidential
Microsoft Confidential
Pull
• Pull does a fetch and then a merge to download the commits and update your local branch in one
command instead of two.
• When to pull
o Use pull to quickly bring your branch up to date with the remote when you aren't worried about reviewing the
changes before merging them into your own branch.
• Pulling updates files in your open project, so make sure to commit your changes before pulling.
Microsoft Confidential
Microsoft Confidential
Push
• Share changes made in commits and branches using the push command
• Push your branches to the remote repository, where Git takes the commits and adds them to an existing
branch on the remote or creates a new branch with the same commits as your local branch.
• When to push
o Use push when you are ready to commit changes to the team’s remote Git repository
Microsoft Confidential
Microsoft Confidential
Protected branches
• Protect important branches by setting branch protection rules
Microsoft Confidential 40
Working with forks
• A fork is a copy of a repository that you manage
• Forks let you make changes to a project without affecting the original repository
• Fetch updates from or submit changes to the original repository with pull requests
• Like copying a repository with two major differences:
o Use a pull request to suggest changes from your user-owned fork to the original repository, also known as the
upstream repository
o Bring changes from the upstream repository to your local fork by synchronizing your fork with the upstream
repository
Microsoft Confidential 41
Collaborative development models
• Development model
o Fork and pull model
▪ Anyone can fork an existing repository and push changes to their personal fork
▪ Don’t need permission to the source repository to push to a user-owned fork
▪ The changes can be pulled into the source repository by the project maintainer
▪ Anyone with push access to the upstream repository can make changes to your pull request
▪ Popular with open-source projects as it allows people to work independently without upfront coordination
o Shared repository model
▪ Collaborators are granted push access to a single shared repository and topic branches are created when changes need to be
made
▪ Pull requests are useful in this model as they initiate code review and general discussion about a set of changes before the
changes are merged into the main development branch
▪ Model more prevalent with small teams and organizations collaborating on private projects.
Microsoft Confidential 42
Pull requests
• Pull requests let you tell others about changes you've pushed to a branch in a repository on GitHub
• Once a pull request is opened, you can discuss and review the potential changes with collaborators and
add follow-up commits before your changes are merged into the base branch
Microsoft Confidential 43
Status checks
• Check if your commits meet the conditions set for the repository you're contributing to
• Based on external processes, such as continuous integration builds, which run for each push you make to a
repository
• See pending, passing, or failing state of status checks next to individual commits in your pull request
Microsoft Confidential 44
Demo 3: Collaborate By
Using GitHub
Microsoft Confidential
Lesson Knowledge Check
1. What is a branch?
2. When do you perform a push operation?
3. Name two branch protection rules that can be configured.
4. What is a fork?
Microsoft Confidential
Lesson Summary
• In this lesson, you learned about:
o Creating and editing commits
o Viewing and comparing commits
o Branches and merges
o Fetch
o Push
o Pull
o Protected branches
o Working with forks
o Collaborative development models
o Pull requests
o Status checks
Microsoft Confidential
Module Summary
• In this module, you learned about:
o Git Overview
o Creating and managing repositories
o Collaborating by using GitHub
Microsoft Confidential
Lab: GitHub Repositories
Microsoft Confidential
Microsoft Confidential