Fundamentals 8 min read

Master the 14 Essential Git Commands You’ll Use 99% of the Time

This guide introduces the fourteen most frequently used Git commands—init, clone, add, commit, push, pull, branch, checkout, merge, status, rebase, stash, and revert—explaining their purpose, typical usage syntax, and practical examples to boost everyday development efficiency.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master the 14 Essential Git Commands You’ll Use 99% of the Time

git init

Creates a new Git repository in the current directory by generating a .git folder that stores all metadata, objects, and references.

git clone

Copies an existing remote repository, including its full commit history and all branches, to a local directory.

git clone https://example.com/owner/project.git

git add

Stages specified files (or patterns) so that their current contents will be included in the next commit.

git add file1.txt src/**/*.js

git commit

Creates a new commit from the staged changes and attaches a descriptive message.

git commit -m "Add new feature"

git push

Uploads local commits to a remote repository, updating the remote branch reference.

git push origin main

git pull

Fetches the latest commits from the remote and merges them into the current branch in a single step.

git pull origin main

git branch

Lists existing branches, creates new branches, or deletes branches.

# List branches
git branch
# Create a new branch
git branch feature-x
# Delete a branch
git branch -d old-branch

git checkout

Switches the working directory to a different branch or restores files from a commit.

git checkout main

git merge

Integrates changes from a source branch into the current branch, producing a merge commit that records both histories.

git merge feature-x

git status

Shows the current branch, staged changes, unstaged modifications, and untracked files.

git status

git rebase

Reapplies commits from the current branch onto another base branch, creating a linear history. Commonly used to move a feature branch onto the latest main before merging.

# Rebase current branch onto main
git rebase main

git stash

Temporarily saves uncommitted changes, allowing you to switch branches without losing work. The stash can later be reapplied or dropped.

# Save changes
git stash
# Apply the most recent stash and remove it from the stash list
git stash pop
# List all stashes
git stash list

git revert

Creates a new commit that undoes the effect of a previous commit (or a range of commits) without rewriting history. Useful for safely rolling back changes that have already been pushed.

# Revert a single commit
git revert a1b2c3d4
# Revert a range of commits (inclusive)
git revert a1b2c3d4..e5f6g7h8

Putting It All Together

These core commands cover the typical daily workflow: initialize a repository, clone existing work, stage and commit changes, synchronize with remotes, manage branches, and safely undo or rearrange history. Mastering them enables efficient collaboration and clean project 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.

Gitcommand-lineVersion Control
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.