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 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 1 of 15 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 sample@example.com
c. At any time, you can review these setting with the git config --list command.
devasc@labvm:~$ git config --list
user.name=SampleUser
user.email=sample@example.com
devasc@labvm:~$
d. Use the cd command to navigate to the devnet-src folder:
devasc@labvm:~$ cd labs/devnet-src/
devasc@labvm:~/labs/devnet-src$
e. Make a directory git-intro and change directory into it:
devasc@labvm:~/labs/devnet-src$ mkdir git-intro
devasc@labvm:~/labs/devnet-src$ cd git-intro
devasc@labvm:~/labs/devnet-src/git-intro$
f. Use the git init command to initialize the current directory (git-intro) as a Git repository. The message
displayed indicates that you have created a local repository within your project contained in the hidden
directory .git. This is where all of your change history is located. You can see it with the ls -a command.
devasc@labvm:~/labs/devnet-src/git-intro$ git init
Initialized empty Git repository in /home/devasc/labs/devnet-src/git-intro/.git/
devasc@labvm:~/labs/devnet-src/git-intro$ ls -a
. .. .git
devasc@labvm:~/labs/devnet-src/git-intro$
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 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 2 of 15 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 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 3 of 15 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 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 4 of 15 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 <sample@example.com>
Date: Sat Apr 18 18:03:28 2020 +0000
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 5 of 15 www.netacad.com
Lab - Software Version Control with Git
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 6 of 15 www.netacad.com
Lab - Software Version Control with Git
devasc@labvm:~/labs/devnet-src/git-intro$
commit b510f8e5f9f63c97432d108a0413567552c07356
Author: Sample User <sample@example.com>
Date: Sat Apr 18 18:03:28 2020 +0000
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 7 of 15 www.netacad.com
Lab - Software Version Control with Git
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 8 of 15 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$
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 9 of 15 www.netacad.com
Lab - Software Version Control with Git
Step 9: Verify the contents of the modified DEVASC.txt in the master branch.
Verify the change to the file.
devasc@labvm:~/labs/devnet-src/git-intro$ cat DEVASC.txt
I am on my way to passing the DevNet 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 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
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 10 of 15 www.netacad.com
Lab - Software Version Control with Git
Automatic merge failed; fix conflicts and then commit the result.
devasc@labvm:~/labs/devnet-src/git-intro$
<output omitted>
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
:
wq
<Enter or Return>
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 11 of 15 www.netacad.com
Lab - Software Version Control with Git
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 12 of 15 www.netacad.com
Lab - Software Version Control with Git
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 13 of 15 www.netacad.com
Lab - Software Version Control with Git
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 14 of 15 www.netacad.com
Lab - Software Version Control with Git
© 2020 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 15 of 15 www.netacad.com