Sync remote

2 snippets in Git

Also written as sync with remote

GitGit

Fetch from Remote

Git · Remote Repositories
Syntax
git fetch [remote] [branch]
Example
git fetch origin
git fetch origin main
git fetch --all
Output
remote: Counting objects: 15, done.
From https://github.com/user/project
   a1b2c3d..f4e5d6c  main -> origin/main

Note Fetch downloads new data but does NOT modify your working directory or merge anything. It's always safe to run. Use --all to fetch from every configured remote.

Pull (Fetch + Merge)

Git · Remote Repositories
Syntax
git pull [remote] [branch]
Example
git pull origin main

# Pull with rebase instead of merge:
git pull --rebase origin main
Output
Updating a1b2c3d..f4e5d6c
Fast-forward
 src/app.js | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Note git pull = git fetch + git merge. Use --rebase to replay your local commits on top of the fetched changes (cleaner linear history). Some teams mandate pull --rebase to avoid unnecessary merge commits.

Frequently asked questions

How does Git handle sync remote?
Git covers this with 2 copy-ready snippets on this page. The "Fetch from Remote" snippet in Git uses `git fetch [remote] [branch]`.
Which command does the Git example use?
The "Fetch from Remote" snippet uses `git fetch [remote] [branch]`, from the Remote Repositories section of the Git cheat sheet.
What other Git snippets are shown for "sync remote"?
Besides "Fetch from Remote", this page also shows "Pull (Fetch + Merge)".
Is there anything to watch out for?
Yes. For "Fetch from Remote": Fetch downloads new data but does NOT modify your working directory or merge anything. It's always safe to run. Use --all to fetch from every configured remote.