14 Essential Git Commands Every Developer Should Master
This guide presents 14 indispensable Git commands—such as init, clone, add, commit, push, pull, branch, checkout, merge, status, rebase, stash, and revert—explaining their purpose, typical usage syntax, and practical examples to help developers efficiently manage repositories and streamline their workflow.
Git init
Initializes a new Git repository in the current directory, creating a .git folder that stores all repository metadata.
Example:
git initGit clone
Clones an existing remote repository, creating a local copy with full history and branches.
Example:
git clone <repository‑url>Git add
Adds specified files to the staging area so they will be included in the next commit.
Example:
git add file1.txt file2.txtGit commit
Creates a new commit that records the staged changes along with a descriptive message.
Example:
git commit -m "Add new feature"Git push
Uploads local commits to a remote repository, updating the remote branch.
Example:
git push origin mainGit pull
Fetches the latest changes from a remote repository and merges them into the current branch.
Example:
git pull origin mainGit branch
Lists, creates, or deletes branches in the repository.
Example:
git branch new-branchGit checkout
Switches the working directory to a different branch.
Example:
git checkout mainGit merge
Integrates changes from one branch into another, creating a new merge commit.
Example:
git merge new-branchGit status
Displays the current state of the working directory, including staged, unstaged, and untracked files.
Example:
git statusGit rebase
Reapplies commits from one branch onto another, creating a linear history.
Example: git rebase main (while on a feature branch)
Git stash
Temporarily saves uncommitted changes so you can switch branches without losing work.
Example:
git stashGit revert
Creates a new commit that undoes the changes introduced by a previous commit.
Example: git revert <commit‑hash> Mastering these fourteen commands covers the most frequently used Git operations, dramatically improving development efficiency and repository management.
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.
