Fundamentals 7 min read

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.

Open Source Linux
Open Source Linux
Open Source Linux
14 Essential Git Commands Every Developer Should Master

Essential Git Commands

git init

Initializes a new Git repository, creating a .git subdirectory that stores all repository metadata.

git init

git 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.txt

git 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 main

git pull

Fetches the latest changes from a remote repository and merges them into the current branch.

git pull origin main

git branch

Lists, creates, or deletes branches in the repository.

git branch new-branch

git checkout

Switches the working directory to a different branch.

git checkout main

git merge

Merges changes from one branch into another, creating a new commit that reflects the merge.

git merge new-branch

git status

Displays the current branch, staged and unstaged changes, and untracked files.

git status

git rebase

Reapplies commits from one branch onto another, effectively moving the base of the branch.

git rebase main

git stash

Temporarily saves uncommitted changes so you can switch branches without losing work.

git stash

git 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.

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.

DevelopmentGitcommand-lineTutorialVersion Controlfundamentals
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.