Skip to content

A brief look at GIT

Note: This is a very simplified explanation of GIT. If you are looking for a more in-depth explanation, please refer to the GIT documentation.

What is git? Git is a distributed version control system that is used to track changes in source code during software development. From the perspective of Network as Code, git allows us to provide version control management for the data model. Users utilize this to be able to track changes. It also can be used to revert changes to the data model, allowing the operators to roll back to a previous version of the data model if needed.

Another advantage of using GIT is that it is designed as a collaborative tool in a distributed architecture of both server and client. This means that multiple users can work on the same data model simultaneously, and changes can be merged together. This is particularly useful in a team environment where multiple engineers are working on the same source data model.

Use local?

One missed common use case for GIT is to use it locally. You can use git to track changes in your local computer files. This allows you to have a history of changes, experiment with new ideas, and easily revert back to previous versions if something goes wrong. In escence GIT is not only a tool for collaboration, but also a powerful tool for managing your own local files.

What do you mean distributed?

When GIT was developed it was designed to be a distributed version control system. This was done on purpose to avoid a “centralized” version control system like existed before with tools like SVN and CVS. In a distributed version control system, every user has a complete copy of the repository on their local machine.

Unique features of GIT

  • Treats everything as snapshots.
  • Most operations are local.
  • Integrity is ensured with SHA-1 checksums.
  • Very fast performance and scalability.

Using GIT with Network as Code

There isn’t anything special about using GIT with Network as Code. The same principles apply as with any other software development project. When using GIT with Network as Code, you will typically have a repository that will contain the data model files, rules and tests.

As you work on the data model, you can keep track of these changes with different methods like branching, committing changes, and pushing them to a location that is shared amongst a team collaborating together.

Eventually you will integrate this repository with some form of automation pipeline that will take the data model and apply it to the network devices ( like Nexus Dashboard in this case). This pipeline could be software like GitLab or GitHub Actions, Jenkins or any other software that allows you to run automation tasks based on changes in a software repository.

Example repository

As part of the Network as Code for Nexus Dashboard, we have created an example repository that you can use to initiate the correct directory structure. This repository contains the base skeleton of code structure that is required to operate Network as Code.

If working to start Network as Code repository with your own data, you will utilize this example repository and then add files and directories as needed to build the data model that represents your network configuration.

This is completed with commands such as git clone to copy the repository to your local machine, and then you can use commands such as git add, git commit, and git push to manage changes to the repository.

When you clone the example repository, you will then remove the .git directory to start with a fresh repository. The reason you do this is because you will not be “pushing” changes to the example repository, as you don’t have permissions to do so. Instead, you will be creating your own repository and pushing changes to that repository.

Commands

A brief explanation of the most common GIT commands you will use when working with Network as Code:

GIT clone

A very common command you will use is git clone. This command allows you to copy a repository from a remote location to your local machine. This is typically the first step when starting to work with a new repository. The local version is a complete copy of the repository you cloned from, inclduing history and branches.

GIT add

The git add command is used to stage changes in your local repository. When you make changes to files in your repository, you need to use this command to tell Git which changes you want to include in the next commit. This allows you to selectively choose which changes to commit, rather than committing all changes at once.

GIT commit

The git commit command is used to create a new commit in your local repository. A commit is a snapshot of the changes you have staged with git add. When you commit changes, you should include a descriptive message that explains what changes were made and why. This helps you and others understand the history of the repository.

GIT push

The git push command is used to upload your local commits to a remote repository. This is how you share your changes with others and keep the remote repository up to date with your local changes. When you push changes, you are sending your commits to the remote repository, making them available for others to see and use.

GIT pull

The git pull command is used to fetch and merge changes from a remote repository into your local repository. This is useful when you want to update your local copy with the latest changes made by others. It combines the git fetch and git merge commands, allowing you to quickly get the latest changes from the remote repository.

GIT branch

The git branch command is used to manage branches in your repository. A branch is a separate line of development that allows you to work on different features or fixes without affecting the main codebase. You can create, list, and delete branches using this command. Branches are useful for isolating changes and collaborating with others.

GIT checkout

The git checkout command is used to switch between branches or restore files in your repository. When you want to work on a different branch, you can use this command to switch to that branch. You can also use it to restore files to a previous state or discard changes.

GIT merge

The git merge command is used to combine changes from one branch into another. This is typically used when you want to integrate changes from a feature branch into the main branch. When you merge branches, Git will automatically handle the differences and create a new commit that represents the combined changes.

GIT log

The git log command is used to view the commit history of your repository. It shows a list of commits, including their commit messages, authors, and timestamps. This is useful for understanding the history of changes made to the repository and tracking down specific changes.

Branching

When working with GIT, you will often use branches. This allows you to separate changes to Network as Code data model. This is very useful and plays a key role when doing pull requests. A pull request is a way to propose changes to a repository and have them reviewed before being merged into the main branch. When you create a pull request, you are asking others to review your changes and provide feedback before they are merged into the main codebase.

When working with Network as Code, you will typically create a new branch for each feature or fix you are working on. This allows you to isolate your changes and work on them without affecting the main codebase. Once you are done with your changes, you can create a pull request to merge your branch into the main branch.

The following tutorial can help you understand branching:

Learn Git Branching

Additional Resources