Essential Git commands for daily development workflow
Initialize a new Git repository
git init
Clone a repository from remote
git clone https://github.com/user/repo.git
Set user configuration
git config --global user.name "Your Name"
Check the status of working directory
git status
Stage files for commit
git add .
Commit staged changes
git commit -m "Add new feature"
View commit history
git log --oneline
Show differences between commits
git diff HEAD~1
List all branches
git branch
Switch to a branch
git checkout feature-branch
Create and switch to new branch
git checkout -b new-feature
Merge branches
git merge feature-branch
Delete a branch
git branch -d feature-branch
Manage remote repositories
git remote add origin https://github.com/user/repo.git
Download objects from remote
git fetch origin
Fetch and merge from remote
git pull origin main
Push commits to remote
git push origin main
Set upstream branch
git push -u origin feature-branch
Reset HEAD to specified commit
git reset --hard HEAD~1
Create new commit that undoes changes
git revert HEAD
Discard changes in working directory
git checkout -- filename
Temporarily save changes
git stash push -m "WIP"
Apply and remove stashed changes
git stash pop
Standard workflow for new features
# Create and switch to feature branch
git checkout -b feature/new-feature
# Make changes and commit
git add .
git commit -m "Add new feature"
# Push to remote
git push -u origin feature/new-feature
# Create pull request on GitHub/GitLab
# After review, merge to main
# Clean up
git checkout main
git pull origin main
git branch -d feature/new-feature
Quick fix for production issues
# Create hotfix branch from main
git checkout main
git pull origin main
git checkout -b hotfix/critical-bug
# Fix the issue
git add .
git commit -m "Fix critical bug"
# Push and merge
git push origin hotfix/critical-bug
git checkout main
git merge hotfix/critical-bug
git push origin main
# Clean up
git branch -d hotfix/critical-bug
Common daily Git operations
# Start of day
git checkout main
git pull origin main
# Work on feature
git checkout feature-branch
git add .
git commit -m "Update feature"
# End of day
git push origin feature-branch
Write clear, descriptive commit messages
Pull before pushing to avoid conflicts
Use feature branches for new development
Check status frequently with git status
Use git stash
to save work in progress