Master the 14 Essential Git Commands Every Developer Needs
This guide introduces fourteen must‑know Git commands—from initializing a repository to reverting changes—explaining their purpose, typical usage examples, and how they streamline daily development, plus a tip on automating analysis with a simple shell script.
git init
Initializes a new Git repository by creating a .git directory that stores all repository metadata.
git clone
Clones an existing repository, creating a local copy with full history and branches.
Example:
git clone <repository‑url>git add
Adds modified 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
Pushes local commits to a remote repository, updating the remote branch.
Example:
git push origin maingit pull
Fetches the latest commits from a remote repository and merges them into the current branch.
Example:
git pull origin maingit branch
Lists, creates, or deletes branches.
Example:
git branch new-branchgit checkout
Switches the working directory to a different branch.
Example:
git checkout maingit merge
Merges changes from one branch into another, creating a new commit that reflects the merge.
Example:
git merge new-branchgit status
Displays the current state of the repository, including staged, unstaged, and untracked files.
Example:
git statusgit rebase
Reapplies commits from one branch onto another, producing a linear history.
Example:
git rebase maingit 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 will significantly boost your development efficiency.
For advanced analysis, you can wrap frequently used Git commands in a shell script (e.g., git_analysis.sh) to display total commit count, branch list, and the latest commit of 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.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
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.
