Essential Git commands for daily development workflow
Initialize a new Git repository
git initClone a repository from remote
git clone https://github.com/user/repo.gitSet user configuration
git config --global user.name "Your Name"Check the status of working directory
git statusStage files for commit
git add .Commit staged changes
git commit -m "Add new feature"View commit history
git log --onelineShow differences between commits
git diff HEAD~1List all branches
git branchSwitch to a branch
git checkout feature-branchCreate and switch to new branch
git checkout -b new-featureMerge branches
git merge feature-branchDelete a branch
git branch -d feature-branchManage remote repositories
git remote add origin https://github.com/user/repo.gitDownload objects from remote
git fetch originFetch and merge from remote
git pull origin mainPush commits to remote
git push origin mainSet upstream branch
git push -u origin feature-branchReset HEAD to specified commit
git reset --hard HEAD~1Create new commit that undoes changes
git revert HEADDiscard changes in working directory
git checkout -- filenameTemporarily save changes
git stash push -m "WIP"Apply and remove stashed changes
git stash popStandard 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-featureQuick 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-bugCommon 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-branchWrite 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