The list of the GIT commands¶
Estimated time to read: 2 minutes
You have three options for pulling changes:
- Merge: This will create a merge commit, combining your local and remote changes.
- Rebase: This will move your local commits to the top of the remote commits, creating a linear history.
- 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.
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:
After you've set your preferred method, you can pull the changes from the remote repository with:
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:
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:
# 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:
# 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:
# 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: