Fundamentals 7 min read

Master the 20 Essential Git Commands Every Developer Needs

This guide walks you through 20 of the most commonly used Git commands—from initial configuration and repository setup to advanced branching, remote collaboration, stashing, and commit conventions—helping you boost personal productivity and streamline team workflows.

JavaScript
JavaScript
JavaScript
Master the 20 Essential Git Commands Every Developer Needs

Basic Configuration Commands

1. Initialize Configuration

Configuring user information is the first step when using Git:

# Configure global username and email
git config --global user.name "FedJavaScript"
git config --global user.email "[email protected]"

# View configuration
git config --list

2. Repository Initialization

Create a new Git repository:

# Initialize a new repository
git init

# Clone a remote repository
git clone <repository-url>

Daily Workflow Commands

3. Status Check

View the current repository status in real time:

# Show working tree status
git status

# Show short status
git status -s

# Show branch information
git branch -v

4. Add and Commit

Basic version‑control operations:

# Add specific file to staging area
git add <file-name>

# Add all changes
git add .

# Commit to local repository
git commit -m "commit message"

# Add and commit together
git commit -am "commit message"

5. Branch Operations

Branch management is a core Git feature:

# Create a new branch
git branch <branch-name>

# Switch branch
git checkout <branch-name>

# Create and switch
git checkout -b <branch-name>

# Delete branch
git branch -d <branch-name>

Advanced Collaboration Commands

6. Remote Repository Operations

Interact with remote repositories:

# Add remote
git remote add origin <repository-url>

# List remotes
git remote -v

# Push to remote
git push origin <branch-name>

# Pull from remote
git pull origin <branch-name>

7. Merge and Rebase

Handle branch merging:

# Merge branch
git merge <branch-name>

# Rebase
git rebase <branch-name>

# Continue rebase after conflicts
git rebase --continue

8. Stash Operations

Temporarily save work progress:

# Save current work
git stash

# List stashes
git stash list

# Apply most recent stash
git stash pop

# Clear all stashes
git stash clear

Advanced Inspection Commands

9. Log Viewing

Inspect commit history:

# Show full log
git log

# One‑line log
git log --oneline

# Graphical log
git log --graph --pretty=oneline --abbrev-commit

10. Diff Comparison

Compare file differences:

# Diff working tree vs index
git diff

# Diff staged vs last commit
git diff --staged

# Diff between two branches
git diff <branch1> <branch2>

Undo and Reset

11. Undo Operations

Correct mistaken actions:

# Discard changes in working tree
git checkout -- <file-name>

# Unstage a file
git reset HEAD <file-name>

# Revert a commit
git revert <commit-id>

12. Reset Operations

Reset versions:

Team Collaboration Advanced

13. Tag Management

Version tagging:

14. Submodules

Manage project dependencies:

15. Workflow Related

Configuration and Optimization

16. Alias Configuration

Shortcut commands to boost efficiency:

17. Ignoring Files

Manage files that should not be version‑controlled:

18. History Management

19. Remote Branch Management

20. Advanced Search

Daily Workflow

Update local code

git pull origin main

Create feature branch

git checkout -b feature/new-feature

Commit regularly

Push to remote

git push origin feature/new-feature

Commit Message Guidelines

Use conventional commit format:

# Feature development
feat: add new feature

# Bug fix
fix: resolve issue #123

# Documentation update
docs: update README.md

Branch Management Strategy

main/master: stable main branch

develop: development branch

feature/*: feature branches

hotfix/*: urgent fix branches

release/*: release branches

Feel free to add more.

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.

workflowsoftware developmentcommand-lineTutorial
JavaScript
Written by

JavaScript

Provides JavaScript enthusiasts with tutorials and experience sharing on web front‑end technologies, including JavaScript, Node.js, Deno, Vue.js, React, Angular, HTML5, CSS3, and more.

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.