Skip to content

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

  1. Open conflicted files and choose the correct content.
  2. Stage the resolved files.
  3. Commit the merge.
git add <file>
git commit