Fundamentals 6 min read

Essential Git Commands for Branching, Stashing, Tagging, and More

This guide compiles the most useful Git commands for managing branches, stashing changes, reverting commits, handling tags, performing common repository tasks, and configuring credential storage, providing concise explanations and practical examples for each operation.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
Essential Git Commands for Branching, Stashing, Tagging, and More

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 all branches git branch -v – show the last commit on each branch git branch -vv – show the current branch with upstream info git branch -b <branch> origin/<branch> – create a local tracking branch from a remote git branch --merged – list branches already merged into the current one git branch --no-merged – list branches not yet merged git branch -d <branch> – delete a local branch git branch -D <branch> – force‑delete a branch git branch origin :<branch> – delete a remote branch git merge <branch> – merge another branch into the current one

Stash Operations

git stash

– temporarily save current modifications git stash apply – re‑apply the most recent stash git stash pop – re‑apply and remove the stash entry git stash list – view all stash entries git stash drop <stash@{n}> – delete a specific stash git stash clear – remove all stashes

Revert Operations

git reset --hard HEAD^

– revert to the previous commit git reset --hard <commit_id> – revert to a specific commit git checkout -- <file> – discard changes in a file (restores from index or last commit) git reset HEAD <file> – unstage a file, moving it back to the working directory

Tag Operations

git tag <name>

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

Common Operations

git push origin test

– push a local branch named test to the remote git rm -r --cached <path> – stop tracking a file or directory git reflog – view the reference log of all actions git log --graph – display a visual branch/merge graph git merge --no-ff -m "msg" <branch> – merge without fast‑forward, preserving a merge commit git check-ignore -v <file> – show which ignore rule applies to a file git add -f <file> – force‑add a file that would otherwise be ignored

Repository‑Related Operations

git init

– initialize a new repository git remote add origin <url> – link a remote repository git pull – fetch and merge changes from the remote git fetch – retrieve all remote branches without merging

Solving Repeated Password Prompts

git config --global credential.helper store

– store credentials so subsequent pushes/pulls won’t ask for a password

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 ControlTaggingbranchingstashing
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

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.