Automation Tools: Git

Let's take a look at the role of Git in network automation and try out some git commands.

Git

Git is natively installed on Linux hosts. However, it should be the first application installed on Windows hosts. This ensures all the future tools installed will integrate. Git commands can be run from the Windows terminal.

Git command reference

Some commonly used Git commands:

git init

This will create a new git repository. This is usually the first command that you will run when starting a new project.

git clone <repository url>

This will clone a repository into a newly-created directory.

git checkout <working branch>

Navigate and work in multiple branches in the same repository by checking out branches. This does not create another copy of the repository locally, it simply changes to a different branch, and Git tracks what branch the changes relate to.

git add

This stages locally changed files, preparing them for the next commit.

git commit

This commits changes to the active branch. These commits have an ID that can be used to track the changes and act as a checkpoint in the change history. It is important- especially in a distributed environment- to commit small and focused changes often and only include specific, related changes per commit.

It is not recommended to accumulate many local changes and bulk commit them into the branch. Committing often allows for multiple people to collaborate on the same branch. Git will track all the distributed changes across the working branch. This is reflected in the branch history, as well as part of the pull request later in the pipeline.

Get hands-on with 1400+ tech skills courses.