Skip to content

The list of the GIT commands

Estimated time to read: 2 minutes

You have three options for pulling changes:

  1. Merge: This will create a merge commit, combining your local and remote changes.
Bash
git config --global pull.rebase false
  1. Rebase: This will move your local commits to the top of the remote commits, creating a linear history.
Bash
git config --global pull.rebase true
  1. Fast-forward only: This will only update your local branch if it can be fast-forwarded, meaning no commits were made in the local branch.
Bash
git config --global pull.ff only

You can set one of these options as your default behaviour using the git config command. For example, to set the default to "merge," run the following command:

Bash
git config --global pull.rebase false

After you've set your preferred method, you can pull the changes from the remote repository with:

Bash
git pull origin main

If you'd like to override the default behaviour for a specific pull operation, you can use the --rebase, --no-rebase, or --ff-only flags directly in the git pull command. For example:

Bash
git pull --rebase origin main

This command will perform a rebase, even if your default setting is "merge" or "fast-forward only."

Modern Git Commands

Git has introduced cleaner alternatives to the overloaded git checkout command. These are now the recommended approach.

git switch — Branch Switching

Replaces git checkout for switching branches, with clearer intent:

Bash
# Switch to an existing branch
git switch main

# Create and switch to a new branch
git switch -c feature/my-feature

# Switch back to the previous branch
git switch -

git restore — File Restoration

Replaces git checkout for restoring file contents, removing ambiguity:

Bash
# Discard unstaged changes to a file
git restore myfile.txt

# Unstage a file (keep changes in working directory)
git restore --staged myfile.txt

# Restore a file to a specific commit
git restore --source=HEAD~2 myfile.txt

git sparse-checkout — Partial Repository Checkout

Useful for large monorepos where you only need specific directories:

Bash
# Enable sparse-checkout
git sparse-checkout init --cone

# Check out only specific directories
git sparse-checkout set services/api libs/shared

# Add another directory
git sparse-checkout add docs/

# Disable sparse-checkout (restore full repo)
git sparse-checkout disable

git maintenance — Automated Repository Health

Keeps your local repository performant with scheduled background tasks:

Bash
# Enable automatic maintenance
git maintenance start

# Run maintenance manually
git maintenance run --auto