14 Essential Git Commands Every Developer Should Master
This guide introduces the 14 most frequently used Git commands—such as init, clone, add, commit, push, pull, branch, checkout, merge, status, rebase, stash, and revert—explaining their purpose, basic usage, and example syntax to boost everyday development efficiency.
Essential Git Commands
git init
Initializes a new Git repository, creating a .git subdirectory that stores all repository metadata.
git initgit clone
Clones an existing repository, creating a local copy that includes the full history and all branches.
git clone <repository-url>git add
Adds changes to the staging area, preparing them for the next commit.
git add file1.txt file2.txtgit commit
Creates a new commit that records staged changes along with a descriptive message.
git commit -m "Add new feature"git push
Pushes local commits to a remote repository, updating the remote branch.
git push origin maingit pull
Fetches the latest changes from a remote repository and merges them into the current branch.
git pull origin maingit branch
Lists, creates, or deletes branches in the repository.
git branch new-branchgit checkout
Switches the working directory to a different branch.
git checkout maingit merge
Merges changes from one branch into another, creating a new commit that reflects the merge.
git merge new-branchgit status
Displays the current branch, staged and unstaged changes, and untracked files.
git statusgit rebase
Reapplies commits from one branch onto another, effectively moving the base of the branch.
git rebase maingit stash
Temporarily saves uncommitted changes so you can switch branches without losing work.
git stashgit revert
Creates a new commit that undoes changes introduced by a previous commit. git revert <commit1>..<commit2> Mastering these commands will greatly improve your development workflow.
For more advanced usage, you can wrap frequently used Git commands in shell scripts. For example, a script can display total commit count, list branches, and show the latest commit on each branch.
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.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
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.
