The sooner you get used to storing your Bash scripts in Git, the better. Version control of your code simplifies future improvements and you can keep track of all changes in an organized fashion. It also allows your peers and colleagues to read the logic you used when you developed your scripts.
Let’s setup your first Git repo:
Enter the directory where the repository will be located.
- Run
git init
- Copy your source code file(s) (or write a first file) into this directory.
- Run
git add *
- Run
git commit -m “Enter information about the script and any changes here."
That’s it! You just created your first Git repository. Let’s take a closer look at the directory .git that was created when you ran git init. We will look at some very important files and directories, to quickly understand the basics of Git.
description
– This file contains a text summary of the project. Enter some text at will.
config
– This file contains settings for the project. Here you will find Boolean variables and numeric values.
hooks
– This directory contains Shell scripts that run before or after events, for instance commit or add. When you first create a Git repository you will find sample scripts here, for commit, push, rebase etc.
objects
– This is where Git stores the internal data for the objects stored in the repository. This is the “useful” data, your source code.
There are several more files and directories, but the above cover the basics fairly well. Over time you will work extensively with Git hooks to customize triggers during Git events.
Well done. You have just started using Git. The first and most important step is done. Now you can start looking into the Git commands by typing git help. Hint: You want to learn how to use Git hooks to automate steps in relation to Git events.