DevNet Associate -Version Control Systems
DevNet Associate -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
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.3.2 Git
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.
Version database
Understanding and Using
4 Version 3
APIs
Version database Version database
Version 2
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
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.
5 Network Fundamentals
Infrastructure and
7
Automation
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
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.
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
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.3.4
3.3 Version Control Systems
What is Branching?
3.3.1 Types of Version Control Systems
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.
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
https://contenthub.netacad.com/devnet/3.3.10 5/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
code review
3.2.4 Model-View-Controller (MVC) documentation
project management
bug tracking
3.3 Version Control Systems
feature requests
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.6
3.3.8 Updating Repositories
Git Commands
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.
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.
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
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.
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.
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.
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.
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.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.
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
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.
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.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.
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:
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.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
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.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.6 Git Commands Please see the official git commit documentation for more details and command line options.
Working directory
3.6 Understanding Data Formats Repository Staging area
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
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:
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.4 Model-View-Controller (MVC) Please see the official git diff documentation for more details and command line options.
(Local)
Master
3.3.3 Local vs. Remote Repositories
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
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
3.2.3 Observer Design Pattern The last commit that local repo knows about
3.3.2 Git
(Local) = + +
Master
3.3.9
3.3.10 .diff Files There are two options for creating a 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>
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.
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
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 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
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:
Branch A
3.3.9 Branching Features
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.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
Branch B
3.3.2 Git
= + +
3.3.3 Local vs. Remote Repositories merge confli
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.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:
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
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.
https://contenthub.netacad.com/devnet/3.3.10 16/17
7/23/24, 8:57 AM DevNet Associate -Version Control Systems
3.3.2 Git
5 Network Fundamentals
Infrastructure and
7
Automation
https://contenthub.netacad.com/devnet/3.3.10 17/17