Unlock the Power of Version Control Now – Lab 02

Learn how to host your Git projects on GitHub, sync local and remote repos, use branches, pull requests, and resolve merge conflicts.


Cisco DevNet Associate course 019 Software Development and Design Utilize common version control operations with Git – Working on a remote repository

Watch Full Demo on YouTube:

Introduction:

In Lab 01, we worked locally with Git — creating repositories, tracking changes, committing code, and managing files.
But in today’s development world, collaboration and backup are key — and that’s where GitHub comes in.

GitHub isn’t just a hosting platform; it’s a hub for teamwork. It allows you to share your code with others, manage project versions, review changes, and merge contributions seamlessly. In this lab, we’ll take your Git skills to the next level by connecting your local repository to GitHub, performing synchronized operations between local and remote environments, and mastering one of the most essential parts of modern DevOps workflows — branching, pull requests, and conflict resolution.

By the end of this lab, you’ll be confident using GitHub to store, sync, and manage your network automation projects efficiently — just like professional developers do.


Learning Objectives

By completing this lab, you will be able to:

  • Create and configure a new GitHub repository as a remote.
  • Connect a local Git project to a GitHub repository.
  • Push and pull changes between local and remote repositories.
  • Create and merge branches using Git and GitHub pull requests.
  • Identify and resolve merge conflicts.
  • Remove unwanted files and maintain a clean project history.

🧩 Task 1 – Use GitHub as a Git Remote

Let’s begin by creating a new home for our project on GitHub.

Step 1-1: Sign in to GitHub

Open your web browser and navigate to github.com. Make sure you’re signed in to your account.

Step 1-2: Create a new repository

Click New Repository and name it:

018_basic_git_operations

For the description, type:

This is a demo

Leave the rest of the settings as default (public visibility, no README, no .gitignore, no license) — we already have a local project we’ll push to GitHub.
Click Create repository.

Step 1-3: Verify no remotes exist locally

Switch to your terminal or command prompt where your local Git project is stored and check if any remotes are configured:

git remote -v

If there’s no output, that means no remote is configured — perfect. We’re starting clean.


Step 1-4: Add the GitHub repository as a remote

Now, let’s connect our local project to GitHub.
Go back to your GitHub repository page and copy the HTTPS URL from the Code button.

Then, in your terminal, run:

git remote add origin https://github.com/{username}/018_basic_git_operations.git

(Replace the username with your own GitHub username.)

To confirm the connection:

git remote -v

You should now see the remote repository listed as origin.


Step 1-5: Push local code to GitHub

Now let’s push our local project to GitHub for the first time:

git push -u origin master

If prompted, enter your GitHub username and password (or token). Once complete, GitHub will now have an exact copy of your local project.


Step 1-6: Verify the files on GitHub

Head back to your GitHub page and refresh the repository.
You should now see all your local files available online.
Congratulations — you’ve officially connected your local and remote repositories!


🧩 Task 2 – Combine Local and Remote Actions

Now that your local and remote repositories are linked, let’s perform a few synchronized actions between them.

Step 2-1: Create a README.md file

Every great project deserves a README file.
In your terminal:

touch README.md

Then open it in VS Code and add:

# VLAN Configuration Generator

A Python script that automatically generates VLAN configuration files for network devices from an inventory list.

Save and close the file.


Step 2-2: Stage and commit the file

Stage and commit your new README file using the standard Git workflow:

git add README.md
git status
git commit -m "Add README file"
git status

Step 2-3: Push the commit to GitHub

Now push your changes:

git push origin master

Then refresh your GitHub page — your new README file should now appear online.


Step 2-4: Confirm .gitignore behavior

Notice that some local folders (like temp/) don’t appear on GitHub.
That’s because they’re listed in .gitignore.
This keeps your remote repository clean by preventing unnecessary or sensitive files from being tracked.


Step 2-5: Delete your local repository

Let’s simulate a real-world disaster — deleting our local project:

cd ..
rm -rf vlan_generator
ls -la

The folder is gone — but thanks to GitHub, your work is safe.


Step 2-6: Clone the project back

To restore your project, clone it from GitHub:

git clone https://github.com/{username}/018_basic_git_operations.git
cd 018_basic_git_operations
tree

Your full project (minus ignored files) is now restored, just as it was before.


Step 2-7: Review commit history

Run:

git log

You’ll see all your commits preserved.
This demonstrates that GitHub is not just a backup — it’s a complete versioned history of your project.


🧩 Task 3 – Develop with Git Branches and Pull Requests

Now that we’ve covered the basics, let’s move into one of Git’s most powerful features: branching.

Step 3-1: Create a new branch

List your branches first:

git branch

Create a new one called distribution_switch:

git branch distribution_switch
git checkout distribution_switch

Confirm your current branch:

git branch -l

Step 3-2: Edit the inventory file

Open inventory.yaml and add:

  - name: distribution_switch_01
    type: cisco_ios

Don’t forget to save the file and then view your changes:

git diff
git status

Step 3-3: Stage and commit

Stage and commit your update:

git add inventory.yaml
git commit -m "Add a distribution switch"
git log

don’t forget to verify the branch’s history with git log


Step 3-4: Push the branch to GitHub

Push the new branch:

git push --set-upstream origin distribution_switch

Step 3-5: Create a pull request on GitHub

On GitHub, you’ll see a prompt to Compare & pull request.
Add a description:

This is a test

Then click Create pull request.


Step 3-6: Merge the pull request

Review the pull request, check the file changes, and if everything looks good, click:

Merge pull request → Confirm merge

You can optionally delete the branch after merging.


Step 3-7: Pull updates to your local repository

Switch back to your local master branch:

git branch
git checkout master
git pull origin master

Now your local repository matches the remote one perfectly.


Step 3-8: Delete the local branch

Finally, clean up your local branches:

git branch -D distribution_switch
git branch

🧩 Task 4 – Work with Multiple Branches and Resolve Merge Conflicts

Let’s now simulate a real-world challenge — merge conflicts.

Step 4-1: Create two feature branches

git branch branch_a
git branch branch_b
git branch

Step 4-2: Work on branch_a

Switch to branch_a:

git checkout branch_a

Edit vlan_generator.py to:

#!/usr/bin/env python3
"""
VLAN Configuration Generator branch_a
Reads devices from inventory file and generates VLAN configs
Test line
"""

Then:

git add vlan_generator.py
git commit -m "Edited the vlan_generator main comment"
git push --set-upstream origin branch_a

Merge branch_a into master using GitHub’s pull request workflow.


Step 4-3: Work on branch_b

Now switch to branch_b:

git checkout branch_b

Edit the same lines but change “branch_a” to “branch_b”:

#!/usr/bin/env python3
"""
VLAN Configuration Generator branch_b
Reads devices from inventory file and generates VLAN configs
Test line
"""

Stage, commit, and push:

git add vlan_generator.py
git commit -m "Edited the vlan_generator main comment 02"
git push --set-upstream origin branch_b

Step 4-4: Merge branch_b and resolve conflict

When you create a pull request for branch_b, GitHub will detect a merge conflict.
You’ll see conflict markers like this:

<<<<<<< branch_b
VLAN Configuration Generator branch_b
=======
VLAN Configuration Generator branch_a
>>>>>>> master

Click Resolve conflicts, choose Accept current change, and Commit merge.
Then finalize the pull request.


Step 4-5: Remove an unwanted file

If you ever add a file by mistake, use:

touch remove.txt
git add remove.txt
git rm -f remove.txt
git status

This removes the file from Git’s tracking cleanly.


🧾 Conclusion

By completing this lab, you’ve moved beyond local version control and entered the collaborative world of remote Git workflows.
You’ve learned how to host projects on GitHub, synchronize changes, use branches for feature development, and handle real-world challenges like merge conflicts.

These skills form the foundation for modern DevOps and network automation workflows. As you continue your journey, you’ll see how Git and GitHub seamlessly integrate into continuous integration, code review, and infrastructure automation pipelines — empowering you to work confidently both solo and in teams.

References:

DevNet Associate – Cisco

Cisco Certified DevNet Expert (v1.0) Equipment and Software List

DevNet Associate Exam Topics

Unlock the Power of Version Control Now – Theory

Unlock the power of Version Control Now – Lab 01 – Work on a local repository


Discover more from IEE

Subscribe to get the latest posts sent to your email.


Discover more from IEE

Subscribe now to keep reading and get access to the full archive.

Continue reading