Git is an open / free tool and considered as distributed Version Control System and used extensively for SCM (Software Configuration Management). Along with GIT, we have Gitlab, Bitbucket – they all fall in the same bracket.
GIT Being DVCS (Distributed Version Control System), git is always considered superior than its Counterpart Centralized Version Control System (CVCS) on the part of speed, reliability, scalability. On top of that it is open source tool and freely availability makes it economical without compromising on security aspect.
Git is an integral part of DevOps Pipeline and probably the starting point of DevOps cycle.
Let us consider the git Architecture consisting of Local and Remote as depicted in Fig-01 .
Local Component comprising of following 3 stages
- Working Directory
- Staging Area
- Local Repo
Remote Component is our remote Repo (GitHub/GitLab etc).
Let us try to understand various git operations / commands by grouping them into following groups
- Local git
- Creating git repository
- Tracking changes
- Reverting changes
- Excluding files
- Remote git
Fig-02 below provides a mindmap view of all the above mentioned git operations groups.
Now let us explore the git operations and carry out end to end SCM activities.
For the subsequent case study it is assumed that we have installed git already on our Linux machine.
Open a Linux terminal
[gdlr_code title=”To Find the version of git installed” active=”no”]
$ git –version
git version 2.7.4
[gdlr_heading tag=”h2″ icon=”icon-diamond” font_weight=”bold” ]
git local operations
- Create git Repo
We’d be cloning an open source project from URL = https://github.com/huihut/stuManager using following command
[gdlr_code title=”Clone a project from GitHub ” active=”no”]
$ git clone https://github.com/huihut/stuManager
This will create a clone for the git project from specified URL into stuManager folder.
We change directory to newly cloned project stuManager by running following commands
[gdlr_code title=”list of working directory” active=”no”]
$ cd stuManager/
$ ls -al
There exists .git folder and its content which we are going to remove by running following command.
[gdlr_code title=”Removing .git folder content” active=”no”]
$ rm -rf .git/
Now we are ready to explore various git operations.
Create git Repo
$ git init
Initialized empty Git repository in /home/devops/zva/stuManager/.git/
stuManager folder is our Working Directory.
.git folder is local Repository (or git repository).
$ git status
This command lets us know all the untracked files in our git project.
- Excluding files for tracking ( .gitignore)
$ touch .gitignore
$ vim .gitignore
After creating this .gitignore file at the project root folder, we again run the below command to check the status of untracked files
$ git status
- Track Local changes
- Add files to staging Area
[gdlr_code title=”Add files to staging Area” active=”no”]
$ git add .
$ git status
Post adding files to staging area, next step would be to move the changes from staging area to local repo through git commit operation
- Commit changes to git repo
$ git commit -m “My First Ever Commit”
$ git status
- View commit history
$ git log
So summarising the git operations we have explored in this article,
- Initialised a git repository at Working Directory after cloning a project from GitHub
- Excluding certain files for tracking with the help of .gitignore
- Adding files to staging area
- Committing changes to Local git repo
- Viewing git status
- Viewing history of commits by git log
In our next article we would continue to explore for pushing the changes from local repo to remote repo and other important relevant operations. Stay tuned for Part 2 of this series. We will be covering more articles which will cover the entire DevOps lifecycle.
Happy Learning (DevOps) !!!
For upcoming DevOps and related programs please visit the following URL
CP-DOF is the only global certification program which takes a participant through a end to end DevOps lifecycle.