Fundamentals 8 min read

Master Git: A Complete Beginner’s Guide to Version Control

This guide walks you through the fundamentals of Git, covering its distributed architecture, core concepts like working directory, staging area, and repository, step‑by‑step installation on Linux, creating local and remote repositories, essential commands such as add, commit, push, handling merge conflicts, and a handy cheat‑sheet of common Git commands.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Git: A Complete Beginner’s Guide to Version Control

Git Overview

Git

is a distributed version‑control system created by Linus Torvalds. Each developer has a full copy of the repository, enabling offline work and flexible collaboration compared to centralized systems like SVN.

Main Concepts

Distributed Version Control

Every clone contains the entire history, allowing work without a central server.

Local commits generate a unique SHA‑1 hash for each snapshot.

Version History and Snapshots

Git records full snapshots of the project at each commit, not just diffs.

Each commit is identified by a SHA‑1 hash.

Branching and Merging

Branches are lightweight; you can create and switch them cheaply.

Merging integrates changes, with Git auto‑resolving conflicts when possible.

Working Directory, Staging Area, Repository

Working Directory – the files you edit.

Staging Area – a temporary area where selected changes are gathered before committing.

Repository – stores all committed snapshots.

Remote Repositories

Platforms like GitHub, GitLab, and Bitbucket host remote repositories for team collaboration.

Installation on Linux (Ubuntu)

sudo apt update
sudo apt install git

Verify the installation with:

git --version
Git version output
Git version output

Creating a Repository

To create a remote repository on Gitee or GitHub, click the “New Repository” button, fill in the details, and copy the git clone URL.

Clone the repository to an empty local directory:

git clone https://gitee.com/yourname/yourrepo.git

After cloning, the directory you see is the working directory; the hidden .git folder holds the actual repository data.

Clone command output
Clone command output

Git Three‑Step Workflow

add

git add filename

Moves the specified file(s) from the working directory to the staging area.

commit

git commit -m "your message"

Creates a new snapshot in the repository from the staged changes. The -m flag records a descriptive message.

push

git push

Uploads local commits to the remote repository, prompting for the remote account credentials.

Handling Conflicts

If the remote repository has diverged, git commit will fail. Synchronize by pulling the latest changes: git pull Resolve any merge conflicts manually, then commit and push again.

Conflict resolution
Conflict resolution

Common Git Commands Cheat‑Sheet

git init

– Initialize a new repository. git clone – Clone a remote repository. git status – Show the status of working directory and staging area. git add – Add files to the staging area. git commit – Commit staged changes. git push – Push local commits to remote. git pull – Fetch and merge remote changes. git merge – Merge another branch into the current one. git branch – List, create, or delete branches. git log – View commit history.

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.

GitVersion ControlCollaborationRepositorybranching
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

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.