0% found this document useful (0 votes)
23 views

DevNet Associate -Version Control Systems

The document provides an overview of Version Control Systems (VCS), detailing their types, including Local, Centralized, and Distributed systems, with a focus on Git as the most popular VCS. It explains the benefits of version control, such as collaboration, accountability, and safety, and describes how Git operates with its unique features like staging areas and file states. Additionally, it highlights the differences between local and remote repositories and emphasizes Git's flexibility and efficiency in managing file changes.

Uploaded by

crio1q
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

DevNet Associate -Version Control Systems

The document provides an overview of Version Control Systems (VCS), detailing their types, including Local, Centralized, and Distributed systems, with a focus on Git as the most popular VCS. It explains the benefits of version control, such as collaboration, accountability, and safety, and describes how Git operates with its unique features like staging areas and file states. Additionally, it highlights the differences between local and remote repositories and emphasizes Git's flexibility and efficiency in managing file changes.

Uploaded by

crio1q
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

7/23/24, 8:57 AM DevNet Associate -Version Control Systems

3.2.1 Show Menu


Introduction
 / Software Development and Design / Version Control Systems

Software Development and


3
3.2.2 The Original Design Patterns 
Design
Version Control Systems
3.2.3 Observer Design Pattern

3.2.4 Model-View-Controller (MVC) 3.3.1

Types of Version Control Systems 


3.3 Version Control Systems 

3.3.1 Types of Version Control Systems Version control, also called version control systems, revision control or source control, is a way to manage changes
to a set of files in order to keep a history of those changes. Think of all the times you have made a copy of a file
3.3.2 Git before modifying it, just in case you want to revert to the original. Version control handles all of that for you.

Version control systems store the master set of files and the history of changes in a repository, also known as a
3.3.3 Local vs. Remote Repositories repo. In order to make a change to a file, an individual must get a working copy of the repository onto their local
system. The working copy is the individual's personal copy of the files, where they can make changes without
3.3.4 What is Branching? affecting others. Some of the benefits of version control are:

It enables collaboration - Multiple people can work on a project (a set of files) at the same time without
3.3.5 GitHub and Other Providers overriding each other's changes.
Accountability and visibility - Know who made what changes, when they made those changes and why.
3.3.6 Git Commands Work in isolation - Build new features independently without affecting the existing software.
Safety - Files can be reverted when a mistake is made.
Work anywhere - Files are stored in a repository, so any device can have a working copy.
3.3.7 Adding and Removing Files

Types of Version Control Systems


3.3.8 Updating Repositories
There are three types of version control systems:

3.3.9 Branching Features


Local
Centralized
3.3.10 .diff Files Distributed

Lab - Software Version Control


3.3.11
with Git
Local Version Control System

3.4 Coding Basics 

3.5 Code Review and Testing  Local computer


3.6 Understanding Data Formats 

Software Development and


3.7
Design Summary  File system
Version database

Understanding and Using


4 
APIs Version 3

5 Network Fundamentals  Version 2

Version 1
Application Deployment and
6 
Security

Infrastructure and
7 
Automation Just like the name states, a Local Version Control System (LVCS) tracks files within a local system. A local version
control system replaces the "make a copy of the file before editing further" scenario. The focus of a local version
control system is mostly to be able to revert back to a previous version. This type of version control isn't meant to
Cisco Platforms and
8  address most of the benefits listed above.
Development

https://contenthub.netacad.com/devnet/3.3.10 1/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
Local version control systems use a simple database to keep track of all of the changes to the file. In most cases,
the system stores the delta between the two versions of the file, as opposed to the file itself. When the user wants
to revert the file, the delta is reversed to get to the requested version.

3.2.1 Introduction
Show Menu
Centralized Version Control System
Software Development and
3
3.2.2 The Original Design Patterns 
Design

3.2.3 Observer Design Pattern Computer 1


Centralized version control
3.2.4 Model-View-Controller (MVC) File system system server

3.3 Version Control Systems 


Checkout

3.3.1 Types of Version Control Systems


Version database

3.3.2 Git

3.3.3 Local vs. Remote Repositories


Computer 2
Version 3
3.3.4 What is Branching? File system

Version 2
3.3.5 GitHub and Other Providers

Version 1
3.3.6 Git Commands

Checkout
3.3.7 Adding and Removing Files

A Centralized Version Control Systems (CVCS) uses a server-client model. The repository (also known as the
3.3.8 Updating Repositories repo), which is the only copy of the set of files and history, is stored in a centralized location, on a server.
Whenever an individual wants to make a change to a file, they must first get a working copy of the file from the
3.3.9 Branching Features repository to their own system, the client.

In a centralized version control system, only one individual at a time can work on a particular file. In order to
3.3.10 .diff Files enforce that restriction, an individual must checkout the file, which locks the file and prevents it from being
modified by anyone else. When the individual is done making changes, they must checkin the file, which applies
Lab - Software Version Control the individual's changes to the master copy in the repo, tags a new version, and unlocks the file for others to make
3.3.11
with Git changes.

3.4 Coding Basics  Distributed Version Control System


3.5 Code Review and Testing  Computer 1 Computer 2

File system File system


3.6 Understanding Data Formats 
Server host
Software Development and
3.7
Design Summary 

Version database
Understanding and Using
4  Version 3
APIs
Version database Version database
Version 2

5 Network Fundamentals  Version 3


Version 1
Version 3

Version 2 Version 2
Application Deployment and
6 
Security
Version 1 Version 1

Infrastructure and
7  A Distributed Version Control System (DVCS) is a peer-to-peer model. The repository can be stored on a client
Automation
system, but it is usually stored in a repository hosting service. When an individual wants to make a change to a file,
they must first clone the full repository to their own system. This includes the set of files as well as all of the file
Cisco Platforms and history. The benefit of this model is that the full repository will be on multiple systems and can be used to restore
8  the repository in the repository hosting service if an event such as data corruption occurs.
Development

https://contenthub.netacad.com/devnet/3.3.10 2/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
In a distributed version control system, every individual can work on any file, even at the same time, because the
local file in the working copy is what is being modified. As a result, locking the file is not necessary. When the
individual is done making the changes, they push the file to the main repository that is in the repository hosting
service, and the version control system detects any conflicts between file changes.
3.2.1 Introduction
Show Menu

Software Development and


3
3.2.2 The Original Design Patterns 
Design 3.3.2

3.2.3 Observer Design Pattern Git 

3.2.4 Model-View-Controller (MVC)


At the time of this writing, the most popular version control system in use is Git. Git is an open source
implementation of a distributed version control system that is currently the latest trend in software development.
3.3 Version Control Systems  Git:

3.3.1 Types of Version Control Systems Is easy to learn


Can handle all types of projects, including large enterprise projects
Has fast performance
3.3.2 Git Is built for collaborative projects
Is flexible
3.3.3 Local vs. Remote Repositories Has a small footprint
Has all the benefits of a distributed version control system
Is free
3.3.4 What is Branching?

A Git client must be installed on a client machine. It is available for MacOS, Windows, and Linux/Unix. Though
3.3.5 GitHub and Other Providers some Git clients come with a basic GUI, Git's focus is on the command line interface, about which we will go into
detail later.

3.3.6 Git Commands


One key difference between Git and other version control systems is that Git stores data as snapshots instead of
differences (the delta between the current file and the previous version). If the file does not change, git uses a
3.3.7 Adding and Removing Files reference link to the last snapshot in the system instead of taking a new and identical snapshot.

3.3.8 Updating Repositories


File view Version view

3.3.9 Branching Features Checkins


Version 1 Version 2 Version 3 Ve

Version 1 Version 2 Version 3 Version 4 A1 A2 A3


3.3.10 .diff Files File A (A1)
A2 A3
B1 B2 B3
File A (A1)
Lab - Software Version Control File B (B1)
3.3.11 B2 B2
with Git C1 C1 C1
File B (B1)
File C (C1)

3.4 Coding Basics 


File C (C1) Snapshot
Reference link
3.5 Code Review and Testing  Git's 3s

Git is organized by threes -- three stages, and three states.


3.6 Understanding Data Formats 

Software Development and Git Three Stages


3.7
Design Summary 

Understanding and Using


4 
APIs

5 Network Fundamentals 

Application Deployment and


6 
Security

Infrastructure and
7 
Automation

Cisco Platforms and


8 
Development

https://contenthub.netacad.com/devnet/3.3.10 3/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems

Repository Working
Staging area
3.2.1 Show Menu
Introduction (.git directory) directory
Software Development and
3
3.2.2 The Original Design Patterns 
Design

Get a copy of the repository (Clone)


3.2.3 Observer Design Pattern

3.2.4 Model-View-Controller (MVC)


Make changes
3.3 Version Control Systems  the files

3.3.1 Types of Version Control Systems

Add changes to stage


3.3.2 Git

3.3.3 Local vs. Remote Repositories


Update repo with changes
3.3.4 What is Branching? (Commit)
There are three stages in Git:
3.3.5 GitHub and Other Providers
repository ( the .git directory)
3.3.6 Git Commands working directory
staging area

3.3.7 Adding and Removing Files


REPOSITORY (.GIT DIRECTORY)

3.3.8 Updating Repositories Because Git is a distributed version control system, each client has a full copy of the repository. When a project
becomes a Git repository, a hidden .git directory is created, and it is essentially the repository. The .git directory
holds metadata such as the files (compressed), commits, and logs (commit history).
3.3.9 Branching Features

WORKING DIRECTORY
3.3.10 .diff Files
The working directory is the folder that is visible in the filesystem. It is a copy of the files in the repository. These
Lab - Software Version Control files can be modified, and the changes are only visible to the user of the client. If the client's filesystem gets
3.3.11 corrupted, these changes will be lost, but the main repository remains intact.
with Git

STAGING AREA
3.4 Coding Basics 
The staging area stores the information about what the user wants added/updated/deleted in the repository. The
3.5 Code Review and Testing  user does not need to add all of their modified files to the stage/repo; they can select specific files. Although it is
called an area, it is actually just an index file located in the .git directory.

3.6 Understanding Data Formats  Three States

Software Development and Since there are three stages in Git, there are three matching states for a Git file:
3.7
Design Summary 

committed - This is the version of the file has been saved in the repository (.git directory).
modified - The file has changed but has not been added to the staging area or committed to the repository.
Understanding and Using
4  staged - The modified file is ready to be committed to the repository.
APIs

5 Network Fundamentals 

3.3.3

Application Deployment and


6  Local vs. Remote Repositories 
Security

Infrastructure and
7  Git has two types of repositories, local and remote.
Automation

A local repository is stored on the filesystem of a client machine, which is the same one on which the git
Cisco Platforms and commands are being executed.
8 
Development
A remote repository is stored somewhere other than the client machine, usually a server or repository hosting
service. Remote repositories are optional and are typically used when a project requires collaboration between a

https://contenthub.netacad.com/devnet/3.3.10 4/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
team with multiple users and client machines.

Remote repositories can be viewed as the "centralized" repository for Git, but that does not make it a CVCS. A
remote repository with Git continues to be a DVCS because the remote repository will contain the full repository,
3.2.1 Show Menu
Introduction which includes the code and the file history. When a client machine clones the repository, it gets the full repository
without needing to lock it, as in a CVCS.
Software Development and
3
3.2.2 The Original Design Patterns 
Design After the local repository is cloned from the remote repository or the remote repository is created from the local
repository, the two repositories are independent of each other until the content changes are applied to the other
3.2.3 Observer Design Pattern branch through a manual Git command execution.

3.2.4 Model-View-Controller (MVC)

3.3.4
3.3 Version Control Systems 

What is Branching? 
3.3.1 Types of Version Control Systems

3.3.2 Git v1.0 v1.1


Master C1

3.3.3 Local vs. Remote Repositories C2 C3 C6


Development

3.3.4 What is Branching? C4 C5


Feature 1

C7
3.3.5 GitHub and Other Providers Feature 2

3.3.6 Git Commands Branching enables users to work on code independently without affecting the main code in the repository. When a
repository is created, the code is automatically put on a branch called Master. Users can have multiple branches
and those are independent of each other. Branching enables users to:
3.3.7 Adding and Removing Files
Work on a feature independently while still benefitting from a distributed version control system
3.3.8 Updating Repositories Work on multiple features concurrently
Experiment with code ideas
Keep production, development, and feature code separately
3.3.9 Branching Features Keep the main line of code stable

3.3.10 .diff Files Branches can be local or remote, and they can be deleted. Local branches make it easy to try different code
implementations because a branch can be used if it is successful and deleted if it is not. Merging a branch back to
Lab - Software Version Control the parent branch is not mandatory.
3.3.11
with Git
Unlike other version control systems, Git's branch creation is lightweight, and switching between branches is
almost instantaneous. Although branches are often visually drawn as separate paths, Git branches are essentially
3.4 Coding Basics 
just pointers to the appropriate commit.

3.5 Code Review and Testing 


C1 v1.1
3.6 Understanding Data Formats 
C2 C3 v1.1
Software Development and Master
3.7
Design Summary 
C4 C5 C6 C7

Understanding and Using


4 
APIs
Feature 1 Development Feat

5 Network Fundamentals  Branches are like a fork in the road, where it starts with the code and history at the point of diversion, then builds
its own path with new commits independently. As a result, branches have their own history, staging area, and
working directory. When a user goes from one branch to another, the code in their working directory and the files
Application Deployment and in the staging area change accordingly, but the repository (.git) directories remain unchanged.
6 
Security
Wherever possible, you should try to use branches rather than updating the code directly to the master branch in
order to prevent accidental updates that break the code.
Infrastructure and
7 
Automation

Cisco Platforms and


8 
Development 3.3.5

https://contenthub.netacad.com/devnet/3.3.10 5/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems

GitHub and Other Providers

3.2.1 Show Menu


Introduction Dealing with projects using Git is often associated with GitHub, but Git and GitHub are not the same. Git is an
implementation of distributed version control and provides a command line interface. GitHub is a service, provided
Software Development and by Microsoft, that implements a repository hosting service with Git.
3
3.2.2 The Original Design Patterns 
Design
In addition to providing the distributed version control and source code management functionality of Git, GitHub
3.2.3 Observer Design Pattern also provides additional features such as:

code review
3.2.4 Model-View-Controller (MVC) documentation
project management
bug tracking
3.3 Version Control Systems 
feature requests

3.3.1 Types of Version Control Systems


GitHub has evolved to support many forms of collaborative coding, including:

3.3.2 Git private repos visible only to designated teams


"social coding" projects that are public, but whose contributors may be anonymous
broad-based open source efforts with many contributors, sometimes numbering in the thousands
3.3.3 Local vs. Remote Repositories

To enable project owners to manage in such widely-disparate scenarios, GitHub introduced the concept of the
3.3.4 What is Branching? "pull request". A pull request is a way of formalizing a request by a contributor to review changes such as new
code, edits to existing code, etc., in the contributor's branch for inclusion in the project's main or other curated
branches. The pull request idiom is now universally-implemented in Git hosting services.
3.3.5 GitHub and Other Providers

GitHub is not the only repository hosting service using Git, others include Gitlab and Bitbucket.
3.3.6 Git Commands

3.3.7 Adding and Removing Files

3.3.6
3.3.8 Updating Repositories
Git Commands 

3.3.9 Branching Features

Setting up Git
3.3.10 .diff Files

After installing Git to the client machine, you must configure it. Git provides a git config command to get and set
Lab - Software Version Control Git's global settings, or a repository's options.
3.3.11
with Git
To configure Git, use the --global option to set the initial global settings.
3.4 Coding Basics 
Command: git config --global key value

3.5 Code Review and Testing  Using the --global option will write to the global ~/.gitconfig file.

3.6 Understanding Data Formats  For each user to be accountable for their code changes, each Git installation must set the user's name and email.
To do so, use the following commands:
Software Development and
3.7
Design Summary 
$ git config --global user.name "<user's name>"
$ git config --global user.email "<user's email>"
Understanding and Using
4 
APIs where <user's name> and <user's email> are the user's name and email address, respectively.

Create a New Git Repository


5 Network Fundamentals 
Any project (folder) in a client's local filesystem can become a Git repository. Git provides a git init command
to create an empty Git repository, or make an existing folder a Git repository. When a new or existing project
Application Deployment and becomes a Git repository, a hidden .git directory is created in that project folder. Remember that the .git directory
6 
Security is the repository that holds the metadata such as the compressed files, the commit history, and the staging area. In
addition to creating the .git directory, Git also creates the master branch.
Infrastructure and
7  Command: git init
Automation

To make a new or existing project a Git repository, use the following command:
Cisco Platforms and
8 
Development
$ git init <project directory>

https://contenthub.netacad.com/devnet/3.3.10 6/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
where the <project directory> is the absolute or relative path to the new or existing project. For a new Git
repository, the directory in the provided path will be created first, followed by the creation of the .git directory.

Creating a Git repository doesn't automatically track the files in the project. Files need to be explicitly added to the
3.2.1 Show Menu
Introduction newly created repository in order to be tracked. Details on how to add files to a repository will be covered later.

Software Development and


3
3.2.2 The Original Design Patterns 
Design
Local computer
3.2.3 Observer Design Pattern

3.2.4 Model-View-Controller (MVC) File system

3.3 Version Control Systems  Repo dir

3.3.1 Types of Version Control Systems .git


HEAD
3.3.2 Git index
objects
3.3.3 Local vs. Remote Repositories ref
... config
3.3.4 What is Branching? branches

3.3.5 GitHub and Other Providers

3.3.6 Git Commands


Get an Existing Git Repository

3.3.7 Adding and Removing Files


With Git, it is easy to get a copy of and contribute to existing repositories. Git provides a git clone command that
clones an existing repository to the local filesystem. Because Git is a DVCS, it clones the full repository, which
3.3.8 Updating Repositories includes the file history and remote-tracking branches.

Command : git clone <repository> [target directory]


3.3.9 Branching Features

where <repository> is the location of the repository to clone. Git supports four major transport protocols for
3.3.10 .diff Files accessing the <repository> : Local, Secure Shell (SSH), Git, and HTTP. The [target directory] is optional and is
the absolute or relative path of where to store the cloned files. If you don't provide the project directory, git copies
Lab - Software Version Control the repository to the location where you executed the command.
3.3.11
with Git

3.4 Coding Basics 


Server host 5
Computer Computer Computer
3.5 Code Review and Testing  File system 3 2 1
1 5 5 5
Repo dir

3.6 Understanding Data Formats  2 4


3
.git
Software Development and
3.7
Design Summary 
Version database Version database Version database

Version 3 Version 3 Version 3


Understanding and Using
4 
APIs
Version 2 Version 2 Version 2

Version 1 Version 1 Version 1


5
5 Network Fundamentals 
5

Application Deployment and


6 
Security When you execute the git clone command, Git:

1. Creates the working directory on the local filesystem with the name of the repository or the specified name, if
Infrastructure and
7  provided.
Automation
2. Creates a .git directory inside the newly created folder.
3. Copies the metadata of the repository to the newly created .git directory.
Cisco Platforms and 4. Creates the working copy of the latest version of the project files.
8 
Development 5. Duplicates the branch structure of the cloned, remote repository and enables tracking of changes made to each
branch, locally and remotely — this includes creating and checking out a local active branch, "forked" from the
cloned repository's current active branch.

https://contenthub.netacad.com/devnet/3.3.10 7/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
Please see the official git clone documentation for more details and command line options.

View the Modified Files in the Working Directory

3.2.1 Show Menu


Introduction What has been changed in the working directory? What files were added in the staging area? Git provides a git
status command to get a list of files that have differences between the working directory and the parent branch.
Software Development and This includes newly added untracked files and deleted files. It also provides a list of files that are in the staging
3
3.2.2 The Original Design Patterns 
Design area. Note that the difference is calculated based on the last commit that the local clone copied from the parent
branch in the Git repository, not necessarily the latest version in the remote repository. If changes have been made
3.2.3 Observer Design Pattern since the repository was cloned, Git won't take those changes into account.

Command : git status


3.2.4 Model-View-Controller (MVC)

In addition to providing list of files, the output of the git status command provides additional information such as:
3.3 Version Control Systems 
Current branch of the working directory
Number of commits the working directory is behind the latest version of the parent branch
3.3.1 Types of Version Control Systems
Instructions on how to update the local repository and how to stage/unstage files

3.3.2 Git Please see the official git status documentation for more details and command line options.

3.3.3 Local vs. Remote Repositories Compare Changes Between Files

Want to know what was changed in a file, or the difference between two files? Git provides a git diff command that
3.3.4 What is Branching? is essentially a generic file comparison tool.

3.3.5 GitHub and Other Providers Command : git diff

Because this command is a generic file difference tool, it includes many options for file comparison. When using
3.3.6 Git Commands this command, the file does not need to be a Git tracked file.

3.3.7 Adding and Removing Files For example, you can:

1. Show changes between the version of the file in the working directory and the last commit that the local clone
3.3.8 Updating Repositories copied from the parent branch in the Git repository:

3.3.9 Branching Features $ git diff <file path>

3.3.10 .diff Files 2. Show changes between the version of the file in the working directory and a particular commit from the file
history:
Lab - Software Version Control
3.3.11
with Git $ git diff <commit id> <file path>

3.4 Coding Basics  3. Show changes between a file’s two commits from the file history. <file path> is the absolute or relative path
of the file to compare and <commit id> is the id of the version of the file to compare.
3.5 Code Review and Testing 
$ git diff <commit id 1> <commit id 2> <file path>

3.6 Understanding Data Formats  4. Show the changes between two files in the working directory or on disk.

Software Development and


3.7  $ git diff <file path 1> <file path 2>
Design Summary

Please see the official git diff documentation for more details and command line options.
Understanding and Using
4 
APIs

5 Network Fundamentals 
3.3.7

6
Application Deployment and Adding and Removing Files 
Security 

Infrastructure and Adding Files to the Staging Area


7 
Automation
After changes have been made to a file in the working directory, it must first go to the staging area before it can be
updated in the Git repository. Git provides a git add command to add file(s) to the staging area. These files being
Cisco Platforms and added to staging can include newly untracked files, existing tracked files that have been changed, or even tracked
8 
Development files that need to be deleted from the repository. Modified files don't need to be added to the working directory
unless the changes need to be added to the repository.

https://contenthub.netacad.com/devnet/3.3.10 8/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
Command : git add

This command can be used more than once before the Git repository is updated (using commit). Also, the same
file can be added to the stage multiple times before a commit. Only the files that are specified in the git add
3.2.1 Show Menu
Introduction command are added to the staging area.

Software Development and To add a single file to the staging area:


3
3.2.2 The Original Design Patterns 
Design

$ git add <file path>


3.2.3 Observer Design Pattern

To add multiple files to the staging area where the <file path> is the absolute or relative path of the file to be
3.2.4 Model-View-Controller (MVC) added to the staging area and can accept wildcards.

3.3 Version Control Systems  $ git add <file path 1> ... <file path n>

3.3.1 Types of Version Control Systems To add all the changed files to the staging area:

3.3.2 Git $ git add .

3.3.3 Local vs. Remote Repositories Remember that Git has three stages, so adding files to the staging area is just the first step of the two-step
process to update the Git repository.

3.3.4 What is Branching?


Please see the official git add documentation for more details and command line options.

3.3.5 GitHub and Other Providers

Before add command


3.3.6 Git Commands

Repository Staging Working directory


3.3.7 Adding and Removing Files (.git directory) area (index)

file 1 file 2 file 3


3.3.8 Updating Repositories

3.3.9 Branching Features


file 4 file 5 file 6
index

3.3.10 .diff Files

Lab - Software Version Control


3.3.11
with Git

3.4 Coding Basics 


Repository Staging Working directory
(.git directory) area (index)
3.5 Code Review and Testing 
file 1 file 2 file 3

file 1 file 4 file 5


3.6 Understanding Data Formats 

file 4 file 5 file 6


Software Development and
3.7
Design Summary  index

After add comand


Removing Files from the Git Repository
Understanding and Using
4 
APIs
There are two ways to remove files from the Git repository.

OPTION 1
5 Network Fundamentals 

Git provides a git rm command to remove files from the Git repository. This command will add the removal of the
Application Deployment and specified file(s) to the staging area. It does not perform the second step of updating the Git repository itself.
6 
Security
Command : git rm

Infrastructure and To remove the specified file(s) from the working directory and add this change to the staging area, use the
7 
Automation following command:

Cisco Platforms and $ git rm <file path 1> ... <file path n>
8 
Development

where <file path> is the absolute or relative path of the file to be deleted from the Git repository.

https://contenthub.netacad.com/devnet/3.3.10 9/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
To add the specified file(s) to be removed to the staging area without removing the file(s) itself from the working
directory, use the following command:

$ git rm --cached <file path 1> ... <file path n>


3.2.1 Show Menu
Introduction

Software Development and This command will not work if the file is already in the staging area with changes.
3
3.2.2 The Original Design Patterns 
Design
Please see the official git rm documentation for more details and command line options.
3.2.3 Observer Design Pattern

3.2.4 Model-View-Controller (MVC) Before remove command

3.3 Version Control Systems  Repository (.git Staging area (index) Working directory
directory)
3.3.1 Types of Version Control Systems

3.3.2 Git
file 1 file 2 file 3

3.3.3 Local vs. Remote Repositories

3.3.4 What is Branching?


file 4 file 5 file 6
3.3.5 GitHub and Other Providers index

3.3.6 Git Commands

3.3.7 Adding and Removing Files

3.3.8 Updating Repositories

3.3.9 Branching Features


Repository (.git Staging area (index) Working directory
3.3.10 .diff Files directory)

Lab - Software Version Control


3.3.11
with Git
file 1 file 2
3.4 Coding Basics 

3.5 Code Review and Testing 

file 3 file 4 file 5 file 6


3.6 Understanding Data Formats  index

Software Development and OPTION 2


3.7
Design Summary 
After remove command
This option is a two step process. First, use the regular filesystem command to remove the file(s). Then, add the
file to stage using the Git command git add that was discussed earlier.
Understanding and Using
4 
APIs
$ rm <file path 1> ... <file path n>
$ git add <file path 1> ... <file path n>
5 Network Fundamentals 
This two step process is equivalent to using the git rm <file path 1> ... <file path n> command. Using
this option does not allow the file to be preserved in the working directory.
Application Deployment and
6 
Security

Infrastructure and
7 
Automation
3.3.8

8
Cisco Platforms and Updating Repositories 
Development 

https://contenthub.netacad.com/devnet/3.3.10 10/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems

Updating the Local Repository with the Changes in the Staging Area

Remember that in Git, changes to a file go through three stages: working directory, staging area, and repository.
3.2.1 Show Menu
Introduction Getting the content changes from the working directory to the staging area can be accomplished with the git add
command, but how do the updates get to the repository? Git provides a git commit command to update the local
Software Development and repository with the changes that have been added in the staging area.
3
3.2.2 The Original Design Patterns 
Design
Command : git commit
3.2.3 Observer Design Pattern
This command combines all of the content changes in the staging area into a single commit and updates the local
Git repository. This new commit becomes the latest change in the Git repository. If there is a remote Git repository,
3.2.4 Model-View-Controller (MVC)
it does not get modified with this command.

3.3 Version Control Systems  To commit the changes from the staging area, use the following command:

3.3.1 Types of Version Control Systems $ git commit

3.3.2 Git It is good software development practice to add a note to the commit to explain the reason for the changes. To
commit the changes from the staging area with a message, use the following command:

3.3.3 Local vs. Remote Repositories


$ git commit -m "<message>"

3.3.4 What is Branching?


If the git commit command is executed without any content in the staging area, Git will return a message, and
nothing will happen to the Git repository. This command only updates the Git repository with the content in the
3.3.5 GitHub and Other Providers staging area. It will not take any changes from the working directory.

3.3.6 Git Commands Please see the official git commit documentation for more details and command line options.

3.3.7 Adding and Removing Files


Before commit command

3.3.8 Updating Repositories Staging Working directory


Repository

3.3.9 Branching Features


file 1 file 4 file 5 file 1 file 4 file 5 file 2 file 3 file 6

3.3.10 .diff Files

Lab - Software Version Control


3.3.11 index
with Git

git commit -m “Adding new files”


3.4 Coding Basics 

3.5 Code Review and Testing 

Working directory
3.6 Understanding Data Formats  Repository Staging area

Software Development and


3.7
Design Summary  file 1 file 4 file 2 file 3 file 6

Understanding and Using


4 
APIs index

After commit command


5 Network Fundamentals  Updating the Remote Repository

In order to share the content changes from the local Git repository with others, the remote Git repository must be
Application Deployment and manually updated. Git provides a git push command to update the remote Git repository with the content changes
6  from the local Git repository.
Security

Command : git push


Infrastructure and
7 
Automation
This command will not execute successfully if there is a conflict with adding the changes from the local Git
repository to the remote Git repository. Conflicts occur when two people edit the same part of the same file. For
Cisco Platforms and example, if you clone the repository, and someone else pushes changes before you, your push may create a
8  conflict. The conflicts must be resolved first before the git push will be successful.
Development

https://contenthub.netacad.com/devnet/3.3.10 11/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
To update the contents from the local repository to a particular branch in the remote repository, use the following
command:

$ git push origin <branch name>


3.2.1 Show Menu
Introduction

Software Development and To update the contents from the local repository to the master branch of the remote repository, use the following
3
3.2.2 The Original Design Patterns  command:
Design

3.2.3 Observer Design Pattern $ git push origin master

3.2.4 Model-View-Controller (MVC) Please see the official git diff documentation for more details and command line options.

3.3 Version Control Systems 


Before push command
3.3.1 Types of Version Control Systems
(Remote)
Origin/Master
3.3.2 Git

(Local)
Master
3.3.3 Local vs. Remote Repositories

3.3.4 What is Branching?

3.3.5 GitHub and Other Providers

3.3.6 Git Commands


(Remote)
Origin/Master

3.3.7 Adding and Removing Files


(Local)
Master
3.3.8 Updating Repositories
After push command
Updating Your Local Copy of the Repository
3.3.9 Branching Features

Local copies of the Git repository do not automatically get updated when another contributor makes an update to
3.3.10 .diff Files the remote Git repository. Updating the local copy of the repository is a manual step. Git provides a git pull
command to get updates from a branch or repository. This command can also be used to integrate the local copy
Lab - Software Version Control with a non-parent branch.
3.3.11
with Git
Command : git pull
3.4 Coding Basics 
To go into more details about the git pull command, when executing the command, the following steps happen:

3.5 Code Review and Testing  1. The local repository (.git directory) is updated with the latest commit, file history, and so on from the remote Git
repository. (This is equivalent to the Git command git fetch.)
2. The working directory and branch is updated with the latest content from step 1. (This is equivalent to the Git
3.6 Understanding Data Formats  command git merge.)
3. A single commit is created on the local branch with the changes from step 1. If there is a merge conflict, it will
Software Development and need to be resolved.
3.7
Design Summary 
4. The working directory is updated with the latest content.

Understanding and Using To update the local copy of the Git repository from the parent branch, use the following command:
4 
APIs
$ git pull

5 Network Fundamentals 
Or

Application Deployment and $ git pull origin


6 
Security

To update the local copy of the Git repository from a specific branch, use the following command:
Infrastructure and
7 
Automation
$ git pull origin <branch>

Cisco Platforms and Please see the official git pull documentation for more details and command line options.
8 
Development

https://contenthub.netacad.com/devnet/3.3.10 12/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems

Before pull command

3.2.1 Show Menu


Introduction (Remote)
Origin/Master
Software Development and
3
3.2.2 The Original Design Patterns 
Design (Local)
Master

3.2.3 Observer Design Pattern The last commit that local repo knows about

3.2.4 Model-View-Controller (MVC)

3.3 Version Control Systems 

3.3.1 Types of Version Control Systems (Remote)


Origin/Master

3.3.2 Git
(Local) = + +
Master

3.3.3 Local vs. Remote Repositories

3.3.4 What is Branching? After pull command

3.3.5 GitHub and Other Providers

3.3.9

3.3.6 Git Commands


Branching Features 

3.3.7 Adding and Removing Files

Creating and Deleting a Branch


3.3.8 Updating Repositories
Branches are a very useful feature of Git. As discussed earlier, there are many benefits of using branches, but one
3.3.9 Branching Features major benefit is that it allows features and code changes to be made independent of the main code (the master
branch).

3.3.10 .diff Files There are two options for creating a branch.

Lab - Software Version Control OPTION 1


3.3.11
with Git
Git provides a git branch command to list, create, or delete a branch.
3.4 Coding Basics 
Command : git branch

3.5 Code Review and Testing  To create a branch, use the following command:

3.6 Understanding Data Formats  $ git branch <parent branch> <branch name>

Software Development and


3.7  where <parent branch> is the branch to branch off of and the <branch name> is the name to call the new
Design Summary
branch.

Understanding and Using When using this command to create a branch, Git will create the branch, but it will not automatically switch the
4 
APIs working directory to this branch. You must use the git switch <branch name> command to switch the working
directory to the new branch.

5 Network Fundamentals  OPTION 2

Git provides a git checkout command to switch branches by updating the working directory with the contents of
Application Deployment and the branch.
6 
Security
Command : git checkout

Infrastructure and
7  To create a branch and switch the working directory to that branch, use the following command:
Automation

$ git checkout -b <parent branch> <branch name>


Cisco Platforms and
8 
Development
where <parent branch> is the branch to branch off of and the <branch name> is the name to call the new
branch.

https://contenthub.netacad.com/devnet/3.3.10 13/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
Deleting a Branch

To delete a branch, use the following command:

3.2.1 Show Menu


Introduction $ git branch -d <branch name>

Software Development and


3
3.2.2 The Original Design Patterns  Please see the official git branch and git checkout documentation for more details and command line options.
Design

3.2.3 Observer Design Pattern GET A LIST OF ALL BRANCHES

To get a list of all the local branches, use the following command:
3.2.4 Model-View-Controller (MVC)

$ git branch
3.3 Version Control Systems 
Or
3.3.1 Types of Version Control Systems

$ git branch --list


3.3.2 Git

Merging Branches
3.3.3 Local vs. Remote Repositories
Branches diverge from one another when they are modified after they are created. To get the changes from one
branch (source) into another (target), you must merge the source branch into the target branch. When Git merges
3.3.4 What is Branching?
the branch, it takes the changes/commits from the source branch and applies it to the target branch. During a
merge, only the target branch is modified. The source branch is untouched and remains the same.
3.3.5 GitHub and Other Providers
For example:

3.3.6 Git Commands

3.3.7 Adding and Removing Files Before merge command

3.3.8 Updating Repositories

Branch A
3.3.9 Branching Features

3.3.10 .diff Files


Branch B

Lab - Software Version Control


3.3.11
with Git git merge BranchA

3.4 Coding Basics 

3.5 Code Review and Testing 


Branch A
3.6 Understanding Data Formats 

Software Development and


3.7  Branch B
Design Summary

Understanding and Using


4 
APIs After merge command
1. At commit#1, Branch B branched off of Branch A.
2. After the branches diverge, someone adds commit#2 to Branch A. Branch B does not get these changes.
5 3. Someone adds commit#3 and commit#4 to Branch B. Branch A does not get these changes.
Network Fundamentals 
4. Someone adds commit#5 to Branch A. Branch B does not get these changes.
5. Now, Branch A and Branch B have diverged by two commits each.
Application Deployment and 6. Let's say that Branch B wants the changes from Branch A since it diverged (commit#2 and commit#5). So,
6  Branch A is the source branch and Branch B is the target branch. In this example, let's state that the commits
Security
were changes in different files. As a result, commit#2 and commit#5 are applied to Branch B and Branch A
remains the same. This is called a fast-forward merge.
Infrastructure and
7 
Automation FAST-FORWARD MERGE

A fast-forward merge is when the Git algorithm is able to apply the changes/commits from the source branch(es)
Cisco Platforms and
8  to the target branch automatically and without conflicts. This is usually possible when different files are changed in
Development
the branches being merged. It is still possible when the same file is changed, but typically when different lines of
the file have been changed. A fast-forward merge is the best case scenario when performing a merge.

https://contenthub.netacad.com/devnet/3.3.10 14/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
In a fast-forward merge, Git integrates the different commits from the source branch into the target branch.
Because branches are essentially just pointers to commits in the backend, a fast-forward merge simply moves the
pointer that represents the HEAD of the target branch, rather than adding a new commit.

3.2.1 Show Menu


Introduction Note that in order to do a fast-forward merge, Git has to be able to merge all of the existing commits without
encountering any conflicts.
Software Development and
3
3.2.2 The Original Design Patterns 
Design MERGE CONFLICTS

3.2.3 Observer Design Pattern Modifying the same file on different branches to be merged increases the chances of a merge conflict. A merge
conflict is when Git is not able to perform a fast-forward merge because it does not know how to automatically
apply the changes from the branches together for the file(s). When this occurs, the user must manually fix these
3.2.4 Model-View-Controller (MVC)
conflicts before the branches can be merged together. Manually fixing the conflict adds a new commit to the target
branch containing the commits from the source branch, as well as the fixed merge conflict(s).
3.3 Version Control Systems 
Branch A

3.3.1 Types of Version Control Systems

Branch B
3.3.2 Git

= + +
3.3.3 Local vs. Remote Repositories merge confli

PERFORMING THE MERGE


3.3.4 What is Branching?

Git provides a git merge command to join two or more branches together.
3.3.5 GitHub and Other Providers
Command : git merge
3.3.6 Git Commands
To merge a branch into the client's current branch/repository, use the following command:

3.3.7 Adding and Removing Files


$ git merge <branch name>

3.3.8 Updating Repositories


where <branch name> is the source branch that is being merged into the current branch

3.3.9 Branching Features When using the git merge command, the target branch must be the current branch/repository, so to merge a
branch into a branch that is not the client's current branch/repository, use the following commands:

3.3.10 .diff Files


$ git checkout <target branch name>
Lab - Software Version Control $ git merge <source branch name>
3.3.11
with Git
where <target branch name> is the target branch and the <source branch name> is the source branch.
3.4 Coding Basics 
To merge more than one branch into the client's current branch/repository, use the following command:
3.5 Code Review and Testing 
$ git merge <branch name 1>...<branch name n>

3.6 Understanding Data Formats 


This is called an octopus merge.
Software Development and
3.7
Design Summary  Please see the official git merge documentation for more details and command line options.

Understanding and Using


4 
APIs

5 Network Fundamentals  3.3.10

Application Deployment and


.diff Files 
6 
Security

What is a .diff file?


Infrastructure and
7 
Automation Developers use a .diff file to show how two different versions of a file have changed. By using specific symbols,
this file can be read by other systems to interpret how files can be updated. The difference is used to implement
Cisco Platforms and the changes by comparing and merging the two versions. Some projects require changes to be submitted through
8  a .diff file as a patch. Because it's all in one file, it's referred to as a unified diff .
Development

The symbols and meanings in a unified diff file are shown below:

https://contenthub.netacad.com/devnet/3.3.10 15/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
+ : Indicates that the line has been added.
- : Indicates that the line has been removed.
/dev/null : Shows that a file has been added or removed.
or "blank": Gives context lines around changed lines.
3.2.1 Show Menu
Introduction @@ : A visual indicator that the next block of information is starting. Within the changes for one file, there may
be multiple.
Software Development and index : Displays the commits compared.
3
3.2.2 The Original Design Patterns 
Design
Example diff for a file named check-network.yml :
3.2.3 Observer Design Pattern

diff --git a/check-network.yml b/check-network.yml


3.2.4 Model-View-Controller (MVC) index 09b4f0c..b1978ca 100644
--- a/check-network.yml
+++ b/check-network.yml
3.3 Version Control Systems  @@ -4,7 +4,7 @@
roles:
3.3.1 Types of Version Control Systems - ansible-pyats
vars:
- snapshot_file: "{{ inventory_hostname }}_bgp.json"
3.3.2 Git
+ snapshot_file: "{{ inventory_hostname }}_routes.json"
tasks:
3.3.3 Local vs. Remote Repositories - set_fact:
snapshot_data: "{{ lookup('file', snapshot_file) | from_json }}"
@@ -13,7 +13,7 @@
3.3.4 What is Branching?
# var: snapshot_data
#
3.3.5 GitHub and Other Providers - pyats_parse_command:
- command: show ip route bgp
+ command: show ip route
3.3.6 Git Commands
compare: "{{ snapshot_data }}"
register: command_output
3.3.7 Adding and Removing Files
The signal can be a "+" or a "-" depending on the order of the hashes.
3.3.8 Updating Repositories
In this format, there are three lines shown above and below the exact changed line for context, but you can spot
the differences by comparing the - line with the + line. One of the changes in this patch is to change the snapshot
3.3.9 Branching Features file name, replacing ...bgp.json with ...routes.json .

3.3.10 .diff Files - snapshot_file: "{{ inventory_hostname }}_bgp.json"


+ snapshot_file: "{{ inventory_hostname }}_routes.json"
Lab - Software Version Control
3.3.11
with Git
You can always look at the difference between two files from a GitHub Pull Request as a unified diff by adding .diff
to the GitHub URL.
3.4 Coding Basics 

3.5 Code Review and Testing 

3.6 Understanding Data Formats  3.3.11

Software Development and Lab - Software Version Control with Git 


3.7
Design Summary 

In this lab, you will explore the fundamentals of the distributed version control system Git, including most of the
Understanding and Using
4  features you'd need to know in order to collaborate on a software project. You will also integrate your local Git
APIs
repository with a cloud-based GitHub repository.

You will complete the following objectives:


5 Network Fundamentals 
Part 1: Launch the DEVASC VM
Part 2: Initializing Git
Application Deployment and
6  Part 3: Staging and Committing a File in the Git Repository
Security
Part 4: Managing the File and Tracking Changes
Part 5: Branches and Merging
Infrastructure and Part 6: Handling Merge Conflicts
7 
Automation Part 7: Integrating Git with GitHub

Cisco Platforms and


8   Software Version Control with Git
Development

https://contenthub.netacad.com/devnet/3.3.10 16/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems

 Software Design Patterns 


3.2 3.4
Coding Basics

3.2.1 Show Menu


Introduction

Software Development and


3
3.2.2 The Original Design Patterns 
Design

3.2.3 Observer Design Pattern

3.2.4 Model-View-Controller (MVC)

3.3 Version Control Systems 

3.3.1 Types of Version Control Systems

3.3.2 Git

3.3.3 Local vs. Remote Repositories

3.3.4 What is Branching?

3.3.5 GitHub and Other Providers

3.3.6 Git Commands

3.3.7 Adding and Removing Files

3.3.8 Updating Repositories

3.3.9 Branching Features

3.3.10 .diff Files

Lab - Software Version Control


3.3.11
with Git

3.4 Coding Basics 

3.5 Code Review and Testing 

3.6 Understanding Data Formats 

Software Development and


3.7
Design Summary 

Understanding and Using


4 
APIs

5 Network Fundamentals 

Application Deployment and


6 
Security

Infrastructure and
7 
Automation

Cisco Platforms and


8 
Development

https://contenthub.netacad.com/devnet/3.3.10 17/17

You might also like