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.
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.gitgit add
Stages specified files (or patterns) so that their current contents will be included in the next commit.
git add file1.txt src/**/*.jsgit 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 maingit pull
Fetches the latest commits from the remote and merges them into the current branch in a single step.
git pull origin maingit 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-branchgit checkout
Switches the working directory to a different branch or restores files from a commit.
git checkout maingit merge
Integrates changes from a source branch into the current branch, producing a merge commit that records both histories.
git merge feature-xgit status
Shows the current branch, staged changes, unstaged modifications, and untracked files.
git statusgit 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 maingit 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 listgit 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..e5f6g7h8Putting 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.
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.
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.)
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.
