3.3.11_lab_-_software_version_control_with_git
3.3.11_lab_-_software_version_control_with_git
Objectives
Part 1: Launch the DEVASC VM
Part 2: Initializing Git
Part 3: Staging and Committing a File in the Git Repository
Part 4: Managing the File and Tracking Changes
Part 5: Branches and Merging
Part 6: Handling Merge Conflicts
Part 7: Integrating Git with GitHub
Background / Scenario
In this lab, you will explore the fundamentals of the distributed version control system Git, including most of
the features you need to know in order to collaborate on a software project. You will also integrate your local
Git repository with the cloud-based GitHub repository.
Required Resources
1 PC with operating system of your choice
Virtual Box or VMWare
DEVASC Virtual Machine
Instructions
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 1 of 23 www.netacad.com
Lab - Software Version Control with Git
b. Next, configure user information to be used for this local repository. This will associate your information
the work that you contribute to a local repository. Use your name in place of "Sample User" for the name
in quotes " ". Use @example.com for your email address.
Note: These settings can be anything you want at this point. However, when you reset these global
values in Part 7, you will use the username for your GitHub account. If you wish, you can use your GitHub
username now.
devasc@labvm:~$ git config --global user.name "SampleUser"
devasc@labvm:~$ git config --global user.email [email protected]
c. At any time, you can review these setting with the git config --list command.
devasc@labvm:~$ git config --list
user.name=SampleUser
[email protected]
devasc@labvm:~$
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 2 of 23 www.netacad.com
Lab - Software Version Control with Git
g. As you work on your project, you will want to check to see which files have changed. This is helpful when
you are committing files to the repo, and you don't want to commit all of them. The git status command
displays modified files in working directory that are staged for your next commit.
This message tells you:
That you are on branch master. (Branches are discussed later in this lab)
The commit message is Initial commit.
There is nothing changed to commit.
You will see that the status of your repo will change once you add files and start making changes.
devasc@labvm:~/labs/devnet-src/git-intro$ git status
On branch master
No commits yet
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 3 of 23 www.netacad.com
Lab - Software Version Control with Git
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
DEVASC.txt
nothing added to commit but untracked files present (use "git add" to track)
devasc@labvm:~/labs/devnet-src/git-intro$
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 4 of 23 www.netacad.com
Lab - Software Version Control with Git
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: DEVASC.txt
devasc@labvm:~/labs/devnet-src/git-intro$
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 5 of 23 www.netacad.com
Lab - Software Version Control with Git
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 6 of 23 www.netacad.com
Lab - Software Version Control with Git
no changes added to commit (use "git add" and/or "git commit -a")
devasc@labvm:~/labs/devnet-src/git-intro$
commit b510f8e5f9f63c97432d108a0413567552c07356
Author: Sample User <[email protected]>
Date: Sat Apr 18 18:03:28 2020 +0000
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 7 of 23 www.netacad.com
Lab - Software Version Control with Git
b. When you have multiple entries in the log, you can compare the two commits using the git diff command
adding original commit ID first and the latest commit second: git diff <commit ID original> <commit ID
latest>. You will need to use your commit IDs. The "+" sign at the end, followed by the text indicates the
content that was appended to the file.
devasc@labvm:~/labs/devnet-src/git-intro$ git diff b510f8e 9f5c4c5
diff --git a/DEVASC.txt b/DEVASC.txt
index 93cd3fb..085273f 100644
--- a/DEVASC.txt
+++ b/DEVASC.txt
@@ -1 +1,2 @@
I am on my way to passing the Cisco DEVASC exam
+I am beginning to understand Git!
devasc@labvm:~/labs/devnet-src/git-intro$
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 8 of 23 www.netacad.com
Lab - Software Version Control with Git
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 9 of 23 www.netacad.com
Lab - Software Version Control with Git
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: DEVASC.txt
devasc@labvm:~/labs/devnet-src/git-intro$
b. Use the git log command to show all commits including the commit you just did to the feature branch.
The prior commit was done within the master branch.
devasc@labvm:~/labs/devnet-src/git-intro$ git log
commit cd828a73102cf308981d6290113c358cbd387620 (HEAD -> feature)
Author: Sample User <[email protected]>
Date: Sat Apr 18 22:59:48 2020 +0000
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 10 of 23 www.netacad.com
Lab - Software Version Control with Git
commit b510f8e5f9f63c97432d108a0413567552c07356
Author: Sample User <[email protected]>
Date: Sat Apr 18 18:03:28 2020 +0000
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 11 of 23 www.netacad.com
Lab - Software Version Control with Git
devasc@labvm:~/labs/devnet-src/git-intro$
b. Verify the appended content to the DEVASC.txt file in the master branch using the cat command.
devasc@labvm:~/labs/devnet-src/git-intro$ cat DEVASC.txt
I am on my way to passing the Cisco DEVASC exam
I am beginning to understand Git!
This text was added originally while in the feature branch
devasc@labvm:~/labs/devnet-src/git-intro$
Step 9:
Deleting a branch.
a. Verify the feature branch is still available using the git branch command.
devasc@labvm:~/labs/devnet-src/git-intro$ git branch
feature
* master
devasc@labvm:~/labs/devnet-src/git-intro$
b. Delete the feature branch using the git branch -d <branch-name> command. .
devasc@labvm:~/labs/devnet-src/git-intro$ git branch -d feature
Deleted branch feature (was cd828a7).
devasc@labvm:~/labs/devnet-src/git-intro$
c. Verify the feature branch is no longer available using the git branch command.
devasc@labvm:~/labs/devnet-src/git-intro$ git branch
* master
devasc@labvm:~/labs/devnet-src/git-intro$
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 12 of 23 www.netacad.com
Lab - Software Version Control with Git
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 13 of 23 www.netacad.com
Lab - Software Version Control with Git
Step 5: Verify the contents of the modified DEVASC.txt in the test branch.
Verify the change to the DEVASC.txt file.
devasc@labvm:~/labs/devnet-src/git-intro$ cat DEVASC.txt
I am on my way to passing the NetAcad DEVASC exam
I am beginning to understand Git!
This text was added originally while in the feature branch
devasc@labvm:~/labs/devnet-src/git-intro$
Step 9: Verify the contents of the modified DEVASC.txt in the master branch.
Verify the change to the file.
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 14 of 23 www.netacad.com
Lab - Software Version Control with Git
Step 11: Attempt to merge the test branch into the master branch.
Attempt to merge the test branch history into the master branch.
devasc@labvm:~/labs/devnet-src/git-intro$ git merge test
Auto-merging DEVASC.txt
CONFLICT (content): Merge conflict in DEVASC.txt
Automatic merge failed; fix conflicts and then commit the result.
devasc@labvm:~/labs/devnet-src/git-intro$
<output omitted>
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 15 of 23 www.netacad.com
Lab - Software Version Control with Git
b. Use the cat command to view the contents of the DEVASC.txt file. The file now contains information to
help you find the conflict. The HEAD version (master branch) containing the word "DevNet" is conflicting
with the test branch version and the word "NetAcad".
devasc@labvm:~/labs/devnet-src/git-intro$ cat DEVASC.txt
<<<<<<< HEAD
I am on my way to passing the DevNet DEVASC exam
=======
I am on my way to passing the NetAcad DEVASC exam
>>>>>>> test
I am beginning to understand Git!
This text was added originally while in the feature branch
devasc@labvm:~/labs/devnet-src/git-intro$
Step 13: Manually edit the DEVASC.txt file to remove the conflicting text.
a. Use the vim command to edit the file.
devasc@labvm:~/labs/devnet-src/git-intro$ vim DEVASC.txt
b. Use the up and down arrow to select the proper line of text. Press dd (delete) on the following lines that
are highlighted. dd will delete the line the cursor is on.
<<<<<<< HEAD
I am on my way to passing the DevNet DEVASC exam
=======
I am on my way to passing the NetAcad DEVASC exam
>>>>>>> test
I am beginning to understand Git!
This text was added originally while in the feature branch
c. Save your changes in vim by pressing ESC (the escape key) and then typing : (colon) followed by wq and
press enter.
ESC
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 16 of 23 www.netacad.com
Lab - Software Version Control with Git
:
wq
<Enter or Return>
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 17 of 23 www.netacad.com
Lab - Software Version Control with Git
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 18 of 23 www.netacad.com
Lab - Software Version Control with Git
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 19 of 23 www.netacad.com
Lab - Software Version Control with Git
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 20 of 23 www.netacad.com
Lab - Software Version Control with Git
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 21 of 23 www.netacad.com
Lab - Software Version Control with Git
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 22 of 23 www.netacad.com
Lab - Software Version Control with Git
End of document
2020 - 2025 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 23 of 23 www.netacad.com