Task |
Command |
Clone a repository |
git clone <repo_url> |
Check current status |
git status |
Add all changes |
git add . |
Commit changes |
git commit -m "Your message here" |
Push changes to main branch |
git push origin main |
Fetch updates from remote |
git fetch origin |
Merge updates if origin/main is ahead |
git merge origin/main |
Pull latest changes (fetch + merge) |
git pull origin main |
View commit history |
git log |
Create a new branch |
git checkout -b <branch_name> |
Switch to an existing branch |
git checkout <branch_name> |
Stash changes |
git stash |
Reapply stashed changes |
git stash pop |
Discard all local changes |
git reset --hard |
View remote repositories |
git remote -v |
Add a new remote |
git remote add <name> <url> |
Delete a branch |
git branch -d <branch_name> |
Delete a remote branch |
git push origin --delete <branch_name> |