Git & GitHub Basics for DevOps Engineers.

Git & GitHub Basics for DevOps Engineers.

Introduction:

This blog introduces Git and GitHub, explaining their utility in version control, which helps track file changes. It further discusses the advantages of distributed version control systems over centralized ones in terms of efficiency, flexibility, and security.

Git is an open source distributed version control system that helps you keep track of the changes you make to your code or files, especially when you are working on a project with other people. Version control basically means we can go back in time and work with a different version of our code.

With Git, you can keep a record of who made changes to what part of a file, and you can revert to earlier versions of the file if needed. Git also makes it easy to collaborate with others, as you can share changes and merge the changes made by different people into a single version of a file. You can think of Git as a diary that records the history of your project, and lets you go back to any previous version if you need to.

GitHub is a website that hosts your Git projects online, so that you can share them with others and collaborate on them. You can think of GitHub as a library that stores your projects and lets you borrow or lend them to other people.

Version control is the idea of keeping track of the changes you make to your files, so that you can undo or redo them if needed. There are two main ways of doing version control: centralized and distributed.

Centralized version control is like having one big book that records all the changes to your project. Everyone who works on the project has to write their changes in the same book, and they have to ask permission from the bookkeeper before they can do so. This can be slow and inconvenient, and if the book gets lost or damaged, you might lose all your work.

A centralized version control system (CVCS) uses a central server to store all the versions of a project's files. Developers "check out" files from the central server, make changes, and then "check in" the updated files. Examples of CVCS include Subversion and Perforce.

Distributed version control is like having many small books that record the changes to your project. Everyone who works on the project has their own book, and they can write their changes in their own book whenever they want. They can also copy each other's books and merge their changes together. This can be fast and flexible, and if one book gets lost or damaged, you can still use another book to recover your work.

A distributed version control system (DVCS) allows developers to "clone" an entire repository, including the entire version history of the project. This means that they have a complete local copy of the repository, including all branches and past versions. Developers can work independently and then later merge their changes back into the main repository. Examples of DVCS include Git, Mercurial, and Darcs.

We use distributed version control over centralized version control because it allows us to work more efficiently, independently, and securely. We can work on our own pace, without waiting for others or relying on a central server. We can also work offline, and choose who we want to share our work with. We can also protect our work from being lost or corrupted, by having multiple copies of it.

How to Install Git on Your Computer 🖥️

Git is a powerful and popular tool for managing your code and collaborating with other developers. Git allows you to track changes, create branches, merge conflicts, and more. But before you can use Git, you need to install it on your computer. I will show you how to install Git on Windows, Mac, and Linux using different methods.

Installing Git on Linux 🐧

Linux's users have many options to install Git, depending on their distribution and package manager. Here are some examples of how to install Git on some common Linux distributions:

- Fedora: Run `sudo dnf install git-all` in Terminal.

- Arch: Run `sudo pacman -S git` in Terminal.

- Debian/Ubuntu: Run `sudo apt install git-all` in Terminal.

- Ubuntu: Run `sudo apt update` followed by `sudo apt install git` in Terminal.

  • sudo apt-get install git: This command installs the main components of Git with minimal dependencies. It does not include a graphical user interface, revision tree visualizer, tools for interoperating with other VCS’s, or a web interface.

  • sudo apt install git-all: This command installs all sub-packages of Git. These include the main Git package, Git documentation, interoperability tools for CVS and SVN, MediaWiki remote helper, email add-on for Git, Git GUI, Git revision tree visualizer, and a web interface.

The choice between git and git-all depends on your requirements. If you don’t need a GUI and are conservative when it comes to disk usage, you might prefer to stick with the git package. However, if you want all the features and tools that come with Git, then git-all would be the better choice.

You can also find instructions for installing Git on other Linux distributions on the [Git website](git-scm.com/download/linux).

Installing Git on Windows 💻

There are a few ways to install Git on Windows, but the easiest one is to use the official Git installer. Here are the steps to follow:

1. Go to the [Git website](git-scm.com) and download the latest version of the installer.

2. Run the installer and follow the instructions on the screen. You can choose the default options or customize them according to your preferences.

3. Open the Windows command prompt or Git Bash (if you selected it during the installation) and type `git version` to verify that Git was installed successfully.

Alternatively, you can also install Git using [GitHub Desktop](desktop.github.com), which is a graphical user interface for Git. GitHub Desktop also comes with a command line version of Git, so you can use both the GUI and the CLI. GitHub Desktop also makes it easy to clone, create, and manage repositories on GitHub.

Another option is to install Git using [Chocolatey](chocolatey.org), which is a package manager for Windows. If you have Chocolatey installed, you can simply run `choco install git` in PowerShell or CMD to install Git.

Installing Git on Mac 🍎

Most versions of macOS already have Git installed, so you may not need to do anything. To check if you have Git, open the Terminal app and type `git version`. If you see a version number, then you have Git. If not, then you need to install it.

One way to install Git on Mac is to use the Xcode Command Line Tools. You can do this by typing `xcode-select --install` in Terminal and following the prompts. This will also install other useful tools for development.

Another way to install Git on Mac is to use the official [Git installer](sourceforge.net/projects/git-osx-installer). Just download it from the [Git website](git-scm.com) and run it. Follow the instructions on the screen and you should have Git installed in no time.

A third option is to install Git using [Homebrew](brew.sh), which is a popular package manager for macOS. If you have Homebrew installed, you can simply run `brew install git` in Terminal to install Git.

Congratulations! 🎉 You have learned how to install Git on your computer using different methods. Now you can start using Git to manage your code and collaborate with other developers.

Do some Practical Tasks:

"Knowing is half the battle, doing it is the remaining half of the battle "

  1. Install Git on your computer (if it is not already installed). You can download it from the official website at git-scm.com/downloads

Commands for Ubuntu:

  1. sudo apt update

  1. sudo apt install git

  1. Create a free account on GitHub (if you don't already have one). You can sign up at github.com

Exercises:

  1. Create a new repository on GitHub and clone it to your local machine.

Command: To clone the repository to local machine

git clone https://github.com/yesicanvinayak/vin-90daysofdevops.git

  1. Make some changes to a file in the repository and commit them to the repository using Git.

Commands:

git add .

git status

git config --global user.email "yesican.vinayak@gmail.com"

git config --global user.name "vinayak"

git commit -m "pushing all work done in 90daysdevops to remote repo"

  1. Push the changes back to the repository on GitHub.

Command:

git push -u origin main

I hope you enjoy the blog post!

If you find the blog helpful, please do like it and share it with your friends. If you have any doubts or questions related to the topics covered in the blog, feel free to ask them in the comments section. I’ll be more than happy to help!