Basic usage
This page covers the minimum Git commands you need for daily work.
First-time setup
# Set your name and email (used in commits)
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
# Optional: make the default branch name "main"
git config --global init.defaultBranch main
Clone the repository
git clone <repository-url>
cd <repository-folder>
Check status
git status
This shows which files changed and what is staged for commit.
Create a branch
git checkout -b feature/short-topic
Stage and commit
# Stage files
git add <file> <file>
# Or stage everything
git add .
# Commit
git commit -m "Short, clear summary"
Sync with remote
# Pull latest changes
git pull
# Push your branch
git push -u origin feature/short-topic
Open a pull request
Create a PR in the Git hosting UI, request a review, and address feedback.
Common fixes
Undo local changes
# Discard changes in a file
git restore <file>
# Unstage a file
git restore --staged <file>
Resolve merge conflicts
- Open conflicted files and choose the correct content.
- Stage the resolved files.
- Commit the merge.
git add <file>
git commit