• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

Roger Perkin

Learn Network Automation

  • Network Automation
    • Ansible Network Automation
      • Ansible Hosts File
      • What is Ansible?
    • Python Network Automation
      • Python for Network Engineers
    • Python Tutorial for Beginners
    • Terraform
    • pyATS
    • Docker
    • GIT
  • Cisco
    • ISE
    • SD WAN Training
    • Password Recovery
    • Software-Upgrade-Guides
    • BGP
    • Data Center
    • WIRELESS
  • CCIE
  • Blog
  • About
    • My Red Special Guitar
  • COURSES
roger perkin ccie cisco consultant header image

Git Tutorial for Beginners

Home » Git Tutorials

What is Git?

Git is the most used version control system in the world today. It was developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel.

If you are looking for the best Git Tutorial for beginners you are in the right place!

The purpose of Git is to manage a project, or a set of files, as they change over time. Git stores this information in a data structure called a repository.

A Git repository contains all the information relating to the changes to a file over time. These can then be used to track changes to a file or roll back changes that have been made in error.

I am going to teach you why you should be using version control and the new world of Git, Github, BitBucket, Gitlab, repositories, repo’s & branches.

Hi, my name is Roger Perkin, I am a network engineer and I use Git for Network Automation.

Check out my Git for Network Engineers course – coming soon

Should Network Engineers learn Git?

A lot of network engineers will take config files and save them to their desktop with a filename like routerbackup-18th-april-v2-osfp-change.txt

Then another engineer will make a change to a device and save another file to their machine called hubrouter-20thapril.txt

We are all guilty of this and it’s a hard habit to break. But with the world of network automation, we as network engineers can learn a lesson from the software development guys who have been using Git for years.

Having a system where you have a single file but can also review all the changes to that file makes a lot of sense in the world of computer networks.

With the advances in network automation network engineers are embracing Git & Github to take control of their code.

Typical use cases are:

  • Network device configuration files
  • Ansible playbooks
  • Python scrips

How to use Git

In order to use Git to track your code you need to install it.

This is a very simple process. Depending on what device you are working with I have listed all the options below – or you can just watch the video.

5 Steps to using Git for the first time

  • Install Git
  • Tell Git some basic info about you
  • Create a folder on your machine
  • Initialise Git within that folder
  • Add files to Git
  • Commit files to the repository

Git Basics – command-line fundamentals

Whilst there are many ways to use Git with a GUI or within your code editor it is very beneficial to understand how Git works under the hood and to learn the command-line fundamentals.

Git vs Github

There is a common misconception that Git and Github are the same thing.

This is not the case.

Git and Github are two completely different things.

Git is a locally installed piece of software that allows you to version control your code on your device.

Github is a web based platform at https://github.com/ which is used to provide an online repository of your code. You connect your local Git installation to your remote Github repository and then sync your code. You can then collaborate with other developers / network engineers.

It’s like Google Drive for your code.

You can also easily provide access to your code to others.

Github provide free plans which give you a public repository, if you want private repositories you have to sign up for a paid plan.

Update: Since Jan 20019 Github now also provides unlimited private repositories with a limited number of collaborators.
https://github.blog/2019-01-07-new-year-new-github/

There are also many other options for places to put your code online e.g. ButBucket and you could even install your own GitLab server on site.


Windows

https://git-scm.com/download/win

MAC

https://git-scm.com/download/win

Debian (e.g. Ubuntu)

apt-get install git

Fedora (e.g. Centos / Red Hat Linux)

yum install git

For more information please checkout – Git vs Github or Gitlab vs Github which is better?


Basic Git Commands

So now you should have Git installed we can start getting into it with some basic Git commands.

For the rest of this post I will be using an Ubuntu installation, but the steps will be the same for all devices.

Check Git Version

To check Git is installed correctly and verify the version issue the command below:

[email protected]:~$ git --version 
git version 2.17.1
[email protected]:~$ 

Next we are going to create a folder for this demo. You will probably already have a folder with your code in that you want to version control we will cover that option later.

Once I have created the folder I enter the command git status and it tells you that Git is not enabled for this folder.

[email protected]:~$ 
[email protected]:~$ mkdir GITfolder
[email protected]:~$ git status 
fatal: not a git repository (or any of the parent directories): .git
[email protected]:~$ 

The reason you get the error fatal: not a git repository is because we have not initialised Git on the folder.

To do that enter the command git init

[email protected]:~$ cd GITfolder 
[email protected]:~/GITfolder$ git init
Initialized empty Git repository in /home/roger/GITfolder/.git/
[email protected]:~/GITfolder$ 

We have now enabled Git to start tracking changes to files within this folder.

So let’s create a file to start tracking, I will also enter a line of text into the file.

[email protected]:~/GITfolder$ 
[email protected]:~/GITfolder$ touch file1.txt
[email protected]:~/GITfolder$ echo "line of text 1" > file1.txt
[email protected]:~/GITfolder$ cat file1.txt
line of text 1
[email protected]:~/GITfolder$

If we now issue the git status command you will see the following.

git tutorial graphic 2 showing output of git status command no commits yet

This image shows us that we are:

  • On the master branch (more on that later)
  • There have been no commits
  • We are not tracking file1.txt

So the next step is to add the file1.txt file into Git so we can start tracking changes to the file.

Git add

git tutorial graphic 3 showing output of adding file1.txt to git

To add the file1.txt file to Git you just enter the command

git add <filename>

Our file, file1.txt is now being tracked by Git.

So let’s make a change to that file and see what Git detect.

[email protected]:~/GITfolder$ echo "Changed the line of text" > file1.txt
[email protected]:~/GITfolder$ 
[email protected]:~/GITfolder$ 
[email protected]:~/GITfolder$ cat file1.txt
Changed the line of text
[email protected]:~/GITfolder$ 

Now we will issue the command git status again to see what has changed.

git tutorial graphic 4 showing output of git status after changing a file

You can see now the Git has detected that a change has been made to the file. It now has a modified status and is showing as red. So let’s add the file again and see what happens.

[email protected]:~/GITfolder$ git add file1.txt
[email protected]untu:~/GITfolder$ git status 
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   file1.txt


Git commit

However, at this time we have not committed the file into Git, the files have not been staged. So to commit the file you enter the command
git commit -m “First Commit”
You have to put a message with the commit with the -m flag and then any comment you want.

[email protected]:~/GITfolder$ git commit -m "First Commit"
[master (root-commit) c9ee375] First Commit
 1 file changed, 1 insertion(+)
 create mode 100644 file1.txt
[email protected]:~/GITfolder$ git status 
On branch master
nothing to commit, working tree clean
[email protected]:~/GITfolder$

You can see now after I enter the command git status that the working tree is clean. This means that all changes to our file have been committed to the Git repository. Because we did not commit the file on the first change it does not have any knowledge of the first text, so I will make one more change to the file and commit it again. Git will then have the 2 changes in it’s log.

Git clone

One of the most used features of Git is Git clone – this enables anyone to pull down some code from a remote repository (typically github.com) and use it on their local machine.

For a more in depth list – check out my specific Git Commands with Examples post

Best way to learn Git

The best way to learn Git is to just get started, so what is stopping you, install Git and start using it today!

Frequently asked questions

Is Git easy to learn?

It is very easy to learn the basics of Git if you are working on your own, you can track changes to your files and roll back with Git. Where it becomes a bit harder is when you are working with other developers. But as with all things, learning Git basics is not hard, but becoming a master takes a bit more time!

What is the best way to learn Git?

I would suggest you do a search on google for the best courses to learn Git and sign up for a basics overview, then once you understand how it works, install Git and just start using it for your day to day code.


git rebase
git stash
git meaning
git delete branch
git rename branch
git merge
git clone
git for windows

Related Searches
git download
git gui
git tutorial
git vs github
git commands
how to use git
what is git and github

Page Contents

  • What is Git?
  • How to use Git
    • 5 Steps to using Git for the first time
  • Git Basics – command-line fundamentals
  • Git vs Github
  • Basic Git Commands
    • Check Git Version
  • Git add
  • Git commit
  • Git clone
  • Best way to learn Git
    • Frequently asked questions
    • Is Git easy to learn?
    • What is the best way to learn Git?
Category: Git Tutorials
Previous Post: « python logo Netmiko
Next Post: Ansible Training Videos »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Sidebar

Hi I'm Roger Perkin,
Based in the UK working as a Technical Architect focussed on Network Automation CCIE #50038
About Roger | Twitter | Linkedin

Recent Posts

  • Hashicorp Vault Tutorial
  • Ansible Tower vs Ansible Automation Platform
  • Cisco Certified DevNet Expert Getting Started Guide
  • Python for Network Engineers Course
  • Gitlab vs Github the Differences Explained

Topics

Network Automation
Ansible
Python for Network Automation
CCIE
Cisco ISE
F5 Certification
BGP
OSPF

Git for Network Engineers

Ansible vs Nornir

Start learning today with my Network Automation Courses

Master Ansible, Python, Git, Nornir, Jenkins and more..


Buy me a coffeeBuy me a coffee

ansible training course

Have you seen my YouTube Channel?

YouTube Subscribe

Let’s get started

Take a look at my premium courses on Ansible, Nornir & Git or buy them all with the Network Automation Bundle!

Network Automation Courses

Navigation

Home

Blog

About

Contact

Network Tools

Python VENV Tutorial

Contact

Get in touch with me here

[email protected]

  • Facebook
  • Instagram
  • Twitter
  • LinkedIn
  • YouTube
Buy me a coffeeBuy me a coffee

YouTube

Don’t forget to take a look at my YouTube Channel

youtube button

Tech

Best Vertical Mouse for RSI

Copyright © 2022 · Roger Perkin · All Rights Reserved · Powered by Mai Theme