🔥 Special Offer: Flat Discount on Your Favorite Courses! Use Coupons GET200OFF GET500OFF
→ Grab Offer Now ←

Commonly Used Git Commands with Examples  


List of Commonly Used Git Commands with Examples

1. Git Configuration Commands
Command Description
git config --global user.name "Your Name" Sets global username
git config --global user.email "you@example.com" Sets global email
git config --list Displays current Git configuration
2. Initialize & Clone Repositories in Git
Command Description
git init Initializes a new Git repository
git clone <repository_url> Clones an existing repository
3. Git Add & Staging Commands
Command Description
git add <file> Stages a specific file
git add . Stages all changes
git reset <file> Unstages a specific file
4. Git Commit Commands for Saving Changes
Command Description
git commit -m "Commit message" Commits changes with a message
git commit --amend -m "New message" Edits the last commit message
git commit -a -m "Message" Stages and commits changes in one command
5. Git Branch Management Commands
Command Description
git branch Lists all branches
git branch <branch-name> Creates a new branch
git checkout <branch-name> Switches to a different branch
git checkout -b <branch-name> Creates and switches to a new branch
git branch -d <branch-name> Deletes a branch
6. Git Merging & Rebasing Commands
Command Description
git merge <branch-name> Merges changes from another branch
git rebase <branch-name> Rebases commits from another branch
7. Git Log & History Viewing Commands
Command Description
git status Shows modified files and staged changes
git diff Shows unstaged changes
git log Displays commit history
8. Git Reset & Undo Changes Commands
Command Description
git checkout -- <file> Discards changes in a file
git reset --soft HEAD~1 Moves back one commit, keeping changes staged
git reset --hard HEAD~1 Moves back one commit and discards changes