Git Basics in Practical DevSecOps Labs: Clone, Commit, Push, and Pull
Git is the most essential tool in any DevSecOps workflow. It powers CI/CD pipelines, Infrastructure as Code, GitOps, and security-as-code practices. This article covers the Git commands you'll use throughout the Practical DevSecOps courses.
Table of Contents
- Initial Git Setup
- Cloning a Repository
- Adding, Committing, and Pushing
- Pulling Changes
- Common Questions
Initial Git Setup
Before using Git, configure your identity:
git config --global user.email "student@practical-devsecops.com"
git config --global user.name "student"
These credentials will be attached to every commit you make.
Cloning a Repository
To download a remote repository to your local machine:
git clone git@gitlab-ce-$STUDENT_ID:root/django-nv.git
Authentication confirmation
On first connection, you may see:
The authenticity of host 'gitlab-ce-$STUDENT_ID (10.x.x.x)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Type yes and press Enter to proceed.
After cloning, explore the repository:
cd django-nv
ls -l
Adding, Committing, and Pushing
In Git, saving changes is a two-step process:
Step 1: Stage changes with git add
Create or modify files, then check the status:
cat > myfile <<EOL
This is my file
EOL
echo "Practical DevSecOps" >> README.md
git status
On branch master
Changes not staged for commit:
modified: README.md
Untracked files:
myfile
Stage the changes:
git add myfile README.md
Step 2: Commit with git commit
git commit -m "Add myfile and update README.md"
[master fb7a678] Add myfile and update README.md
2 files changed, 2 insertions(+)
create mode 100644 myfile
The -m flag provides a commit message.
Step 3: Push to the remote repository
git push
Verify your changes on GitLab at https://gitlab-ce-$STUDENT_ID.$LAB_DOMAIN_URI/root/django-nv.
| Credential | Value |
|---|---|
| Username | root |
| Password | pdso-training |
Pulling Changes
To download changes made by others (or via the GitLab web UI):
git pull
Note: You may use the GitLab web UI to edit files during exercises. You can also make all changes via the Git CLI if you prefer.
Common Questions
| Question | Answer |
|---|---|
What's the difference between git add and git commit? |
git add stages changes (marks them to be included). git commit saves the staged changes to the repository history. |
| Why do I need to configure my email and name? | Every commit records the author's identity. Without it, git commit will warn you. |
What does git status show? |
It displays which files are staged, modified, untracked, or already committed. |
| Can I undo a commit? | Use git revert to create a new commit that undoes changes, or git reset to move back in history (use with caution). |
| Do I need internet to use Git locally? | No. Git works offline for local operations. You only need internet for git push and git pull. |
For additional learning, see Git Basics — Automation Step by Step YouTube Playlist.
Wrap-Up
Mastering git clone, git add, git commit, git push, and git pull is the foundation for every CI/CD pipeline exercise you'll encounter. These five commands cover the vast majority of Git operations in the Practical DevSecOps courses.