Fundamentals 15 min read

Master Git: History, Core Commands, Branches, Tags, and Server Deployment

This comprehensive guide walks you through Git's origins, environment setup, installation, essential commands, workflow states, branching strategies, tag management, as well as detailed steps for deploying GitLab, using GitHub, and selecting client tools, all illustrated with clear diagrams and practical examples.

dbaplus Community
dbaplus Community
dbaplus Community
Master Git: History, Core Commands, Branches, Tags, and Server Deployment

History of Git

Linus Torvalds created Git in C over two weeks in 2005 after the Linux kernel grew too large for manual patch submissions and the free BitKeeper license was withdrawn. Git was designed as a fast, distributed version‑control system that stores complete snapshots of the project state.

Git history diagram
Git history diagram

Preparing the Git Environment

Install Git on the workstation and create a working directory where Git can track file changes.

Initializing a Repository

Run git init to create an empty repository. The repository can be cloned to other machines, providing a fully distributed version store without a central server.

Common Git Commands

git add

– stage file contents for commit git bisect – locate buggy changes via binary search git branch – list, create, or delete branches git checkout – switch to a branch or restore files git clone – copy a repository to a new directory git commit – record staged changes git diff – show differences between commits or the working tree git fetch – download objects and refs from another repository git grep – search for patterns in files git init – create a new empty repository git log – display commit history git merge – combine histories of two branches git mv – move or rename a file, directory, or symlink git pull – fetch and integrate changes from a remote git push – update remote refs with local commits git rebase – reapply commits on top of another base git reset – move HEAD to a specified state git rm – remove files from working tree and index git show – display various types of objects git status – show the state of the working directory git tag – create, list, delete, or verify a GPG‑signed tag

Basic Git Workflow

Git tracks three states for each file:

Committed – stored in the Git database.

Modified – changed but not yet staged.

Staged – ready to be committed.

Typical workflow:

Modify files in the working directory.

Stage changes with git add.

Commit the staged snapshots with git commit.

Git workflow diagram
Git workflow diagram

Branch Management

Branches provide isolated workspaces. Create a feature branch (e.g., camera-feature) to avoid affecting the stable master branch. After completing work, merge the feature branch back into master.

Branch diagram
Branch diagram

Creating a Branch

Use git branch <name> to create and git checkout <name> to switch to the new branch.

Merging a Branch

Combine a feature branch into the current branch with git merge <branch>.

Merge diagram
Merge diagram

Resolving Merge Conflicts

If automatic merging fails, Git marks conflicted files. Manually edit the conflicted sections, then stage the resolved files with git add and commit.

Conflict example
Conflict example

Tag Management

Tags mark important points such as releases. Creating a tag is instantaneous and provides a stable reference to a specific commit.

Tag diagram
Tag diagram

Deploying GitLab on CentOS 7

Install required dependencies.

Add the GitLab package repository and install the gitlab-ee (or gitlab-ce) package.

Configure /etc/gitlab/gitlab.rb as needed and run gitlab-ctl reconfigure.

Open HTTP (port 80) and SSH (port 22) in the firewall, then access the web UI via the host name to complete initial setup.

Firewall configuration
Firewall configuration
Package installation
Package installation
GitLab start
GitLab start

Configuring SSH for GitLab

Generate an SSH key pair on the client ( ssh-keygen -t rsa -b 4096), add the public key ( id_rsa.pub) in the GitLab web UI under Settings → SSH Keys , and test the connection with ssh -T [email protected].

Using GitHub as a Hosted Service

Create a GitHub account, then create a new repository (public or private). Clone the repository via SSH: git clone [email protected]:username/repo.git Upload an SSH public key in Settings → SSH and GPG keys to enable secure push/pull operations.

Git Client Tools

Graphical clients such as SourceTree provide visual interfaces for staging, committing, branching, and merging, simplifying Git workflows.

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.

GitLabGitGitHubTaggingbranching
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

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.