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.
Install Git
Use the package manager or compile from source. For example:
yum install gitOr 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 --versionInitialize 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 --listObtain a Repository
You can either create a repository in an existing directory or clone an existing one.
Initialize in current directory
git initThis creates a
.gitsubdirectory containing all necessary metadata.
Clone a repository
git clone https://github.com/libgit2/libgit2 git clone https://github.com/libgit2/libgit2 mylibgitTrack and Commit Changes
Check the status of the working tree:
git statusStage new files:
git add READMECommit staged changes:
git commit -m "Add README"Or amend the previous commit:
git commit --amendUndo Operations
Reset a file from the index:
git reset HEAD libgit2Discard local modifications:
git checkout -- CONTRIBUTINGRemote Repositories
View configured remotes:
git remote -vAdd a new remote:
git remote add origin git@server:project.gitFetch and pull:
git fetch origin git pullPush changes:
git push origin masterDelete a remote branch:
git push origin --delete serverBranch Management
Create, list, and delete branches:
git branch testing git branch -d testingSwitch branches:
git checkout testingOr create and switch in one step:
git checkout -b featureMerge branches:
git merge hotfixIf 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 masterAvoid 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.0Aliases
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 statusFor a complete reference, see the official Git documentation at https://git-scm.com/book/en/v2/Getting-Started-Git-Basics.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.