Fundamentals 17 min read

Comprehensive Git Guide: Installation, Configuration, Basic Operations, Branching, and Remote Management

This article provides a detailed tutorial on installing Git on various platforms, configuring user information and aliases, managing .gitignore files, performing core repository actions such as init, add, commit, diff, and status, as well as advanced branch, tag, and remote repository operations using the command line.

Architecture Digest
Architecture Digest
Architecture Digest
Comprehensive Git Guide: Installation, Configuration, Basic Operations, Branching, and Remote Management

This guide explains how to install Git on Linux (using sudo yum install git or sudo apt-get install git ) and macOS (via the terminal or the official installer at git-scm.com).

It then covers Git configuration, emphasizing the importance of setting global user name and email with git config --global user.name "Your Name" and git config --global user.email [email protected] . It describes the three configuration levels ( --system , --global , and repository‑specific .git/config ) and shows how to query them.

Creating convenient aliases is demonstrated, for example git config --global alias.br branch and git config --global alias.ci commit . The .gitignore syntax is explained, including comment lines, glob patterns, and negation, with sample entries such as *.c , !stream.c , and build/ .

Basic repository operations are presented: initializing a repository with git init , adding files ( git add . , git add *.c , git add test.c ), checking status ( git status and git status --short ), viewing differences ( git diff , git diff --staged ), committing changes ( git commit -m "message" , git commit -a -m "msg" ), removing files ( git rm fileName , git rm -f fileName ), moving files ( git mv src dest ), and examining history with various git log options.

The article explains how to amend the last commit ( git commit --amend ), reset staged files ( git reset HEAD fileName ), and discard local changes ( git checkout -- filename ).

Tag management is covered, showing how to list tags ( git tag ), create annotated tags ( git tag -a v1.0 -m "msg" ) or lightweight tags ( git tag v1.0 ), push tags to a remote ( git push origin v1.4 , git push origin --tags ), and inspect tag details with git show v1.4 .

Branch operations are detailed: creating branches ( git branch dev or git checkout -b dev ), switching ( git checkout dev ), merging ( git merge dev ), deleting ( git branch -d dev , git branch -D dev ), listing branches with status ( git branch -v , git branch --merged , git branch --no-merged ), and rebasing ( git rebase master experiment followed by git checkout master and git merge experiment ).

Remote repository commands are illustrated: cloning ( git clone <url> [dirName] ), viewing remotes ( git remote -v , git remote show origin ), adding a remote ( git remote add rp [email protected]:repo.git ), fetching ( git fetch rp ), pulling ( git pull ), pushing ( git push origin master ), renaming ( git remote rename old new ), and removing ( git remote rm name ) remote definitions.

Tracking branches are explained, with commands such as git checkout --track origin/dev and setting upstream with git branch -u origin/dev or git branch -vv .

Overall, the article serves as a practical reference for developers to master Git’s essential and advanced features.

configurationgitCommand-lineversion controltaggingRepository ManagementBranching
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

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.