Fundamentals 44 min read

Master Git: From Installation to Advanced Branch Management

This comprehensive guide walks you through installing Git, configuring user information, initializing repositories, tracking and committing changes, managing branches, handling remotes, using tags, rebasing, and creating command aliases, all illustrated with clear examples and screenshots.

Ops Development Stories
Ops Development Stories
Ops Development Stories
Master Git: From Installation to Advanced Branch Management

Install Git

Use the package manager or compile from source. For example:

yum install git

Or compile:

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.12.2.tar.gz
tar -zxvf git-2.12.2.tar.gz
cd git-2.12.2
./configure --prefix=/usr
make all doc info
sudo make install install-doc install-html install-info
git --version

Initialize Git

Set your identity so that each commit records your name and email:

git config --global user.name "wanger"
git config --global user.email [email protected]

Check configuration:

git config --list
Git configuration output
Git configuration output

Obtain a Repository

You can either create a repository in an existing directory or clone an existing one.

Initialize in current directory

git init

This creates a

.git

subdirectory containing all necessary metadata.

Clone a repository

git clone https://github.com/libgit2/libgit2
git clone https://github.com/libgit2/libgit2 mylibgit
Cloned repository structure
Cloned repository structure

Track and Commit Changes

Check the status of the working tree:

git status
git status output
git status output

Stage new files:

git add README

Commit staged changes:

git commit -m "Add README"

Or amend the previous commit:

git commit --amend
Commit summary
Commit summary

Undo Operations

Reset a file from the index:

git reset HEAD libgit2
git reset output
git reset output

Discard local modifications:

git checkout -- CONTRIBUTING
git checkout output
git checkout output

Remote Repositories

View configured remotes:

git remote -v
git remote -v output
git remote -v output

Add a new remote:

git remote add origin git@server:project.git

Fetch and pull:

git fetch origin
git pull
git fetch output
git fetch output

Push changes:

git push origin master
git push output
git push output

Delete a remote branch:

git push origin --delete server
delete remote branch
delete remote branch

Branch Management

Create, list, and delete branches:

git branch testing
git branch -d testing

Switch branches:

git checkout testing
checkout testing branch
checkout testing branch

Or create and switch in one step:

git checkout -b feature

Merge branches:

git merge hotfix
merge output
merge output

If conflicts occur, edit the conflicted files, resolve the markers, and commit the result.

Rebase

Reapply commits onto another base to keep a linear history:

git rebase master

Avoid rebasing branches that have already been shared with others.

Tags

List, create, and push tags:

git tag
git tag -a v1.0 -m "Release 1.0"
git push origin v1.0
list tags
list tags

Aliases

Define shortcuts for frequently used commands:

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git alias configuration
git alias configuration

For a complete reference, see the official Git documentation at https://git-scm.com/book/en/v2/Getting-Started-Git-Basics.

gitCommand-lineversion controlBranchingAliasesTagsRemote Repositories
Ops Development Stories
Written by

Ops Development Stories

Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.

0 followers
Reader feedback

How this landed with the community

login 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.