Nabugu - stock.adobe.com

Tip

An introduction to Git for network engineers

Git can be a useful tool for network engineers who manage complex infrastructure, especially as networking increasingly overlaps with software, automation and DevOps.

Gone are the days when network professionals manually verify configuration changes in a network. In this evolving digital society, network teams can use network automation, DevOps and infrastructure as code to streamline configuration management.

Nowadays, many enterprises have teams distributed around the world, often with a mix of remote and hybrid employees. Managing those employees -- and the networks that support them -- is easier thanks to automation and version control systems (VCSes), such as Git.

Network engineers can use Git to manage network configuration files, work collaboratively on projects, monitor changes made to configurations and improve documentation.

How Git works

Git is a distributed VCS that uses a database to track changes made by network engineers or developers as they work on the same project. A VCS stores different files and records any changes made to them. It enables teams to compare or roll back changes and see who has modified the file.

Git helps eliminate the blame game. As someone makes changes, Git can protect the code or network configurations by enabling users to check each change. For example, a code commit saves a code change and sends it to the repository. Teams can use hierarchical folders and tags to indicate within the code who made a change and when.

Git uses a checksum to verify repository integrity. It detects corruption using a Secure Hash Algorithm 1 cryptographic hash represented by a checksum string with 40 hexadecimal characters.

Here is some Git terminology to understand before diving into specific commands:

  • Local workspace. A workspace is the working directory on a local machine where users make changes to project files. It's a project folder where users store in-progress projects before adding them to a repository.
  • Staging area. Users can format and review commits in a staging area before committing them to a repository. This index tracks working directory changes.
  • Head or local repository. A repository is the GIT folder that tracks all project files and history. Users can add files, commit changes and delete files in the repository, which is located on a workstation.

The power of Git is the ability to use branches, which are separate versions of the main repository. Branches enable users to collaborate on different versions simultaneously without modifying the main project version. Users can choose to merge changes to the main project when ready or keep their versions separate. Branches are similar to working on different directories in Linux.

Hands-on with Git

The best way to understand Git as a network engineer is to practice daily. Below are some basic commands to get started with Git.

1. Git config

The git config command sets the user information for different repositories. Users can run this command to describe usernames, emails and configuration settings specific to each user.

Git config screenshot

2. Git init

The git init command creates a new repository and initializes a GIT file that contains a subdirectory with all repository metadata and data structures.

Git init screenshot

3. Git clone

The git clone command downloads a remote repository from a specified URL. The command creates a working copy of a repository so users can edit, commit and roll back changes to the remote repository.

Git clone screenshot

4. Git status

The git status command shows the state of a Git repository and its files. For example, it indicates whether a file has been modified, added, staged or deleted. It also shows untracked files that have been added or modified, as shown in red here.

Git status screenshot

5. Git add

The git add command adds all specified files and their contents from a local workspace, as shown in green here, to the staging area, or index. This command is necessary before performing a commit.

Git add screenshot

6. Git commit

The git commit command bundles and records a history of all staged changes to a local repository. This command tracks authors, timestamps and commit messages. Use git commit -m to include a commit message, as shown here.

Git commit screenshot

7. Git log

The git log command lists the commits made in a repository in chronological order. The log includes information such as the commit hash, author, date and commit message.

Git log screenshot

Networking use cases for Git

Below are some ways network engineers can use Git with version control, network configuration and script management.

Version control use cases Network configuration use cases Script management use cases
Configuration management Easily tracking changes made to configuration over time Bash scripts to automate daily tasks
Documentation Tracking network topology changes and other network-related changes Automating daily tasks using Python scripts
Troubleshooting Tinkering configurations and rollback while troubleshooting
Tracking code changes and code management Network equipment backups

Git vs. Ansible vs. Python vs. CLI

Git, Ansible and Python are all free, open source tools that help with software development and infrastructure management. But each tool has its own purpose.

Git is a distributed VCS that is both fast and scalable. It tracks changes primarily for source code and software development.

Ansible is an automation tool that helps with system configuration and management. It can automate tasks on network devices, servers and cloud environments.

Python is a programming language and remains the de facto standard for network automation. It is popular because of its clear syntax, readability and debugging capabilities.

The CLI is a general interface that enables users to interact with a computer. Git is a specific tool that users can employ through the command line.

Git can interact with both Python and Ansible to help with source code management. For example, Ansible can use Git to fetch source code from a repository as part of an automation workflow.

Benefits of Git

Developers and network engineers favor Git as a distributed VCS for its speed and scalability. It can be difficult to manage complex network infrastructure without Git. Other benefits of Git include the following:

  • Git is the most used VCS in software development. It has rich documentation and a vast community, which improves collaboration and automation.
  • Git's branching capabilities help distributed teams around the world work together.
  • It is open source and free.

Challenges of Git

While Git offers many benefits, it does have some challenges. Some of those disadvantages are the following:

  • Git isn't easy to learn in the beginning, especially for network engineers new to software development concepts.
  • It takes practice to understand the tool, terminology, features and processes.
  • Git can consume large amounts of storage resources, due to repository size.

Best practices for Git

The following are some best practices network engineers should use when working with Git:

Git is a powerful tool. As automation and software become more prominent in networking, the ability to use Git could emerge as a key skill for network engineers to manage complex infrastructure.

Next Steps

How to use NAPALM for efficient network management

Dig Deeper on Network management and monitoring