Fundamentals 8 min read

Git Version Control: Installation, Configuration, Core Commands, Branch & Tag Management, and Code Export

This guide walks through installing and configuring Git, explains the working directory, staging area, and repository concepts, demonstrates common commands for initializing, committing, branching, tagging, reverting changes, and shows how to archive code and upgrade Git on CentOS.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Git Version Control: Installation, Configuration, Core Commands, Branch & Tag Management, and Code Export

1. Install Git Version Control System

Git's working directory, staging area, and repository meanings

Working directory: the visible folder on your computer.

Staging area: also called stage or index, stored in .git/index.

Repository: the hidden .git folder that holds all history.

Installation and configuration commands:

yum install git -y<br/>git --version<br/>git config --global user.name "chenkang"   # set user name<br/>git config --global user.email "[email protected]"   # set email<br/>git config --global color.ui "true"

Initialize a repository: git init Add files and commit: git add .<br/>git commit -m 'add three file' Rename a file and commit: git mv file1 file4<br/>git commit -m 'change file name' File comparison:

git diff file3               # working tree vs. staging<br/>git diff --cached file3      # staging vs. repository

Reverting changes:

# revert a staged file<br/>git reset HEAD file3<br/># revert an unstaged file<br/>git checkout -- file3

Branch management:

# create a new branch<br/>git branch dev01<br/># switch to it<br/>git checkout dev01<br/># merge master into dev01<br/>git merge master -m 'merge master into dev01'<br/># switch back to master and merge dev01<br/>git checkout master<br/>git merge dev01 -m 'merge dev01 into master'

Branching principles:

master should be stable and used only for releases.

development occurs on dev (or feature) branches.

individual developers work on personal branches and merge into dev.

use --no-ff for a true merge commit to preserve history.

3. Git Tag Management

Tags give commits a readable alias.

# create a lightweight tag<br/>git tag v1.2<br/># delete a tag<br/>git tag -d v1.2<br/># create an annotated tag<br/>git tag -a v1.0 -m 'optimized and bug‑fixed' a119962<br/># show tag details<br/>git show v1.1

4. Exporting Code with Git Archive

Archive a branch:

git archive --format tar.gz --output "./output.tar.gz" master

Archive a specific commit or directory:

# archive a different branch<br/>git archive --format tar.gz --output "./output.tar.gz" dev01<br/># archive a specific commit<br/>git archive --format tar.gz --output "./output.tar.gz" 5ca16ac0d603603<br/># archive selected directories from master<br/>git archive --format tar.gz --output "./output.tar.gz" master <name1> <name2>

5. Upgrading Git on CentOS

Steps to replace the old Git version (1.8.x) with a newer one (2.23.0):

# install build dependencies<br/>yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc -y<br/>yum install gcc perl-ExtUtils-MakeMaker -y<br/># remove old Git<br/>yum remove git -y<br/># download source tarball<br/>wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.23.0.tar.xz<br/># extract and build<br/>tar xf git-2.23.0.tar.xz<br/>cd git-2.23.0<br/>make prefix=/usr/local/git all<br/>make prefix=/usr/local/git install<br/># add new Git to PATH
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Gitcommand-lineInstallationVersion ControlTaggingbranching
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.