Fundamentals 11 min read

Master Uncommon Git Commands: From Basics to Advanced Rebase Techniques

This article introduces essential and less‑common Git commands, explains basic operations like clone, pull, branch, and commit, then dives into advanced topics such as merge versus rebase, cherry‑pick, reset versus revert, and HEAD reference syntax, providing clear examples and visual illustrations.

Tencent IMWeb Frontend Team
Tencent IMWeb Frontend Team
Tencent IMWeb Frontend Team
Master Uncommon Git Commands: From Basics to Advanced Rebase Techniques

Basic Commands

git clone [email protected]:username/repo.git

– clone a remote repository to the local machine. git pull origin master – fetch the remote master branch and merge it into the current branch. git branch -a – list all local and remote branches. git checkout -b bugFix – create a new branch named bugFix and switch to it (omit -b if the branch already exists). git status – show the current working tree status. git add . – stage all changes in the current directory. git commit -m 'message' – commit staged changes with a message. git push – push local commits to the remote branch. git tag v1.0 – create a tag v1.0 on the current commit.

Advanced Commands

Merge vs Rebase

Git integrates changes from different branches mainly via merge or rebase . merge creates a special commit with two parents, preserving the full history, while rebase rewrites commits onto another base, producing a linear history.
git checkout master; git merge bugFix

After merging, a new commit (e.g., C4) appears on master that contains all changes from both branches. git checkout bugFix; git rebase master Rebase copies the commits from bugFix onto the tip of master, resulting in a linear sequence of commits.

Extended Rebase Usage

git rebase targetBranch originBranch

– rebase originBranch onto targetBranch without switching branches. git rebase -i commitid – interactively edit, reorder, squash, or drop commits starting from the specified commitid.

Cherry‑Pick

git cherry-pick copies a specific commit from anywhere in the commit graph onto the current HEAD .
git checkout master; git cherry-pick C2

Reset vs Revert

git revert HEAD creates a new commit that undoes the changes of the specified commit, preserving history; git reset moves the branch pointer backward, discarding commits as if they never existed.
git reset HEAD~1
git revert HEAD

Using reset after a push can cause conflicts, whereas revert safely adds a compensating commit.

HEAD^n and HEAD~n

HEAD^ moves one parent up; HEAD~3 moves three commits back. These operators can be chained (e.g., HEAD^2~3 ).
git branch -f master HEAD~3

This forces master to point to the third ancestor of the current HEAD.

Conclusion

The guide summarizes several less‑common Git commands, encouraging regular practice so they become familiar tools for everyday development.

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.

GitmergerebaseVersion Controlresetcherry-pickreset vs revert
Tencent IMWeb Frontend Team
Written by

Tencent IMWeb Frontend Team

IMWeb Frontend Community gathering frontend development enthusiasts. Follow us for refined live courses by top experts, cutting‑edge technical posts, and to sharpen your frontend skills.

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.