Fundamentals 9 min read

Essential Git Commands: Branching, Stashing, Reverting, Tagging, and Common Operations

This article provides a comprehensive guide to essential Git commands, covering branch creation and management, stash usage, commit rollback, tag manipulation, common repository operations, ignoring files, and password‑less authentication, with practical examples and links for each command.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Essential Git Commands: Branching, Stashing, Reverting, Tagging, and Common Operations

Branch Operations:

git branch

– create a new branch git branch -b – create and switch to a new branch

git checkout – switch branches

git branch – list branches

git branch -v – view last commit on each branch

git branch -vv – view current branch details

git branch -b origin/branch-name – create local tracking branch from remote

git branch --merged – list branches merged into current

git branch --no-merged – list branches not merged

git branch -d branch-name – delete local branch

git branch -D branch-name – force delete branch

git branch origin :branch-name – delete remote branch

git merge branch-name – merge branch into current

Stash Operations:

git stash – stash current changes

git stash apply – apply most recent stash

git stash pop – apply and drop stash

git stash list – list stashes

git stash drop stash@{0} – delete specific stash

git stash clear – clear all stashes

Revert Operations:

git reset --hard HEAD^ – revert to previous commit git reset --hard <commit_id> – revert to a specific commit git checkout -- <file> – discard changes in a file (from index or working tree) git reset HEAD <file> – unstage a file, keeping changes in working directory

Tag Operations:

git tag tag-name

– create a tag on current commit git tag tag-name <commit_id> – tag a specific commit git tag -a tag-name -m "description" – create annotated tag git tag – list all tags git show tag-name – show tag details git tag -d tag-name – delete local tag git push origin tag-name – push tag to remote git push origin --tags – push all tags git push origin :refs/tags/tag-name – delete remote tag

General Operations:

git push origin test

– push local branch to remote git rm -r --cached <path> – stop tracking a file or directory git reflog – view reference log of commands git log --graph – visualize branch merge graph git merge --no-ff -m "merge description" <branch> – merge without fast‑forward git check-ignore -v <file> – see which ignore rule applies git add -f <file> – force‑add ignored file

Creating a Repository:

git init

– initialize repository git remote add origin <url> – add remote git pull – fetch and merge git fetch – fetch all remote branches

Ignoring Files Already Tracked:

git update-index --assume-unchanged <file>

– ignore a single tracked file git rm -r --cached <path> – stop tracking a directory or file

Cancel Ignoring:

git update-index --no-assume-unchanged <file>

– resume tracking

Password‑less Pull/Push:

git config --global credential.helper store

– cache credentials for future operations

To conclude, if this article helped you on the path to becoming an advanced architect, feel free to share it, join the architect community, and reply with “加群” to get into the technical discussion group.

These are the practical resources shared over the years:

1. 第七期打卡送书5本 (May 1 – June 1)

2. ERP system with inventory, finance, and production modules

3. SpringBoot backend management project with workflow

4. Ready‑to‑use OA system

5. SpringBoot + Vue complete food‑delivery system with source code

Sharing and forwarding is the greatest support – thank you! ❤️

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.

GitVersion ControlTaggingbranchingstash
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

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.