Master Git Basics: From Installation to Remote Collaboration
This article introduces Git as a free, open‑source distributed version‑control system, explains why developers use it, describes its three‑stage architecture, walks through installation, repository initialization, configuration, common commands for status, branching, committing, and shows how to work with remote repositories on GitHub.
What Is Git?
Git is a free, open‑source distributed version‑control system that tracks source‑code changes throughout software development and coordinates collaborative work among engineers.
Why Use Git?
Track every change to files, making it easy to revert to any version.
Maintain an orderly project history and identify who made changes.
Facilitate collaboration regardless of developers' locations.
Develop new features while preserving the existing codebase.
Git vs. GitHub
Git creates a timeline of changes without storing files online, while GitHub provides a popular online platform for hosting Git repositories.
Git Stages
Git has three stages: working directory, staging area, and local repository.
Working directory : where you create, modify, or delete files.
Staging area : a pre‑commit zone; files are moved here when marked for commit.
Local repository : stores committed changes permanently.
Installing Git
https://www.git-scm.com/After installation, verify with:
git --versionInitializing a Repository
Create a folder for your project and run: git init This creates a .git folder that tracks all changes.
Configuring User Name and Email
git config --global user.name "Your name"
git config --global user.email "[email protected]"Use --global for user‑level settings or omit it for repository‑level configuration.
Git Status
Untracked : new files not yet committed.
Modified : files changed after the last commit.
Staged : files marked for the next commit.
Committed : snapshots stored in the local repository.
Check status with:
git statusBranches
Branches provide isolated workspaces so developers can develop features or fix bugs without affecting the main line (usually master or main).
Basic Workflow
Create a file and add content: echo "Introduction to Git" > a.txt Stage the file: git add a.txt Commit with a message:
git commit -m "Add introduction file"Viewing Commit History
git logFor a concise view, use git log --oneline.
Working with Remote Repositories (GitHub)
Create a repository on GitHub, then add it as a remote:
git remote add github-repo https://github.com/youruser/yourrepo.gitVerify remotes: git remote -v Push a branch to the remote:
git push github-repo masterCloning a Remote Repository
git clone https://github.com/youruser/yourrepo.gitThis creates a local copy linked to the remote.
Updating Local Repository
Fetch changes from the remote without merging: git fetch Merge fetched changes into the current branch: git merge github-repo/master Or combine fetch and merge with:
git pull github-repo masterSummary
The article covered essential Git commands for installation, repository setup, configuration, status checking, branching, committing, viewing history, and interacting with remote repositories.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
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.
