Blog 11 Git & Shell Scripting Made Easy: Learn Version Control and Automation

Git, Version Control, and Shell Scripting Explained Simply

Git, Version Control, and Shell Scripting Explained in Simple Terms

If you are starting your journey into software development or DevOps, two important concepts you will always come across are Version Control (like Git) and Shell Scripting. In this article, I will explain these in a simple, human-friendly way with practical examples.


What is Version Control?

Imagine you are working on a Word document and you keep saving multiple copies: project_v1.doc, project_v2.doc, project_final.doc. This is how developers used to manage software versions manually — but it quickly becomes messy.

Version Control Systems (VCS) solve this by keeping track of changes in your code. It tells you:

  • What was changed?
  • Who changed it?
  • When it was changed?
  • Why the change happened? (via commit messages)

And the best part — you can always go back to an older version if something breaks.

Example

  • 20-Dec-2024 → Application deployed to production
  • 21-Dec-2024 → Issue occurred
  • 19-Dec-2024 → Rollback code to this version (stable)

Centralized vs Distributed Version Control

Centralized (Example: SVN)

In a centralized system, there is only one server where the code is stored. Developers connect to it to work. Sounds simple, right? But the problem is:

  • If the server is down, nobody can work.
  • If the server crashes, the entire project history may be lost.

Distributed (Example: Git)

In a distributed system like Git, every developer has a full copy of the code and the history on their machine. This makes it very safe and reliable:

  • Work continues even if the main server is down.
  • Every developer is like a backup of the project.
Centralized: One big office → If the office is locked, nobody works.
Distributed: Each employee has a full office desk at home → Work continues anywhere.
  

Popular Git Platforms

Git is just the version control tool. To use it with teams, we need online platforms (called Git hosting services):

  • GitHub → Most popular, public as well as private projects.
  • GitLab → Good for DevOps features.
  • Bitbucket → Often used with Atlassian tools like Jira.
  • Azure Repos → Hosted by Microsoft for enterprise users.
  • AWS CodeCommit → Amazon’s Git hosting solution.

Basic Git Workflow Step-by-Step

  1. Create a Repository (a folder to store your code online).
  2. Clone the Repository to your laptop:
    git clone https://github.com/daws-78s/shell-script.git
  3. Edit your code using an editor like VS Code (free and widely used).
  4. Add files to staging area:
    git add file-name   # adds a specific file
    git add .           # adds all files
          
  5. Commit your changes with a message:
    git commit -m "Added a new feature"
  6. Push code to the remote repository:
    git push origin main

That’s it! This is the basic cycle: Clone → Edit → Add → Commit → Push.


Shell Scripting Basics

A shell script is like writing a set of Linux/Unix commands in a file so that you can run them together instead of typing them one by one. The file usually ends with .sh.

Types of Shell

  • Bash (most popular)
  • Korn Shell (ksh)
  • C Shell (csh)
  • Z Shell (zsh)

Shebang (#!)

The very first line of a shell script begins with #! (called shebang). It tells the system which interpreter to use. Example:

#!/bin/bash

How to Run a Shell Script

sh script-name.sh
bash script-name.sh
  

Variables

Variables store values (like numbers, text, etc.). Example:

x=10
y=5
echo "x=$x, y=$y"
  

If you change the value of x in one place, it reflects everywhere it is used. This follows the DRY principle (Don't Repeat Yourself).

Key Shell Script Features

  1. Variables → Store data in a reusable way.
  2. Data types → Numbers, strings, arrays, etc.
  3. Conditions → If-else statements.
  4. Loops → For and while loops for repetition.
  5. Functions → Group commands that can be reused.
  6. Arguments → Pass values at runtime without editing the script.

Example: Passing Arguments

sh 04-variables.sh arg1 arg2
  

Here arg1 and arg2 are runtime values given to the script when running it.


Final Thoughts

Git and Shell Scripting are two essential skills for anyone entering the IT or DevOps world. Git helps you manage and collaborate on projects without losing track of versions, while shell scripting automates repetitive Linux tasks and improves productivity.

If you master these, you have already taken a big step toward becoming a strong DevOps or software professional 🚀.

All rights reserved by kalyan kalavena no copy or edit without permission

Comments

Popular Posts