Essential Git Commands and Their Usage
The article presents a comprehensive guide to essential Git commands, detailing their syntax, purpose, and typical usage scenarios, making it a practical reference for developers learning version control and command‑line operations.
This article presents a comprehensive guide to essential Git commands, detailing their syntax, purpose, and typical usage scenarios for developers learning version control.
git config
git config --global user.name "[name]" git config --global user.email "[email address]"Sets the global username and email for commits.
git init git init [repository name] Creates a new repository.
git clone git clone [url] Clones a repository from the given URL.
git add git add [file] or git add * Stages a file or all files for commit.
git commit git commit -m "[commit message]" Records staged changes in the repository history. git commit -a Commits all tracked changes.
git diff git diff – shows changes not staged. git diff --staged – shows staged vs. latest. git diff [first branch] [second branch] – compares two branches.
git reset git reset [file] – unstage a file. git reset [commit] – undo commits while keeping changes. git reset --hard [commit] – discard all changes and reset to a commit.
git status git status Displays the state of the working directory and staging area.
git rm git rm [file] Removes a file from the working directory and stages the deletion.
git log git log Shows commit history of the current branch. git log --follow [file] – shows history of a specific file, including renames.
git show git show [commit] Displays metadata and changes of a specific commit.
git tag git tag [commitID] Creates a tag on a specific commit.
git branch git branch – lists local branches. git branch [branch name] – creates a new branch. git branch -d [branch name] – deletes a branch.
git checkout git checkout [branch name] – switches to an existing branch. git checkout -b [branch name] – creates and switches to a new branch.
git merge git merge [branch name] Merges the specified branch into the current branch.
git remote git remote add [name] [remote URL] Adds a remote repository.
git push git push [name] master – pushes the master branch. git push [name] [branch] – pushes a specific branch. git push --all [name] – pushes all branches. git push [name] :[branch] – deletes a remote branch.
git pull git pull [repository URL] Fetches and merges changes from a remote repository.
git stash git stash save – saves local modifications. git stash pop – restores the most recent stash. git stash list – lists all stashes. git stash drop – discards the most recent stash.
Images illustrating each command are included throughout the original article.
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.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
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.
