clone, remote, fetch, pull, push
Intermediate Git CLI VS Code UI IntelliJ UI GitLab UI GitHub UI
Why this matters
Four commands, four different effects, and beginners routinely reach for the wrong one. This lesson puts them on one picture and shows the output of each, so that "I pulled and my changes vanished" and "I pushed but nobody can see it" stop happening.
The picture
| Command | Direction | Changes on your side | Changes on the remote |
|---|---|---|---|
git clone |
remote → you | creates the whole repository, origin, and the working tree |
nothing |
git fetch |
remote → you | the remote-tracking bookmarks (origin/main) only |
nothing |
git pull |
remote → you | bookmarks and your branch and your files | nothing |
git push |
you → remote | the bookmark, to match | the branch you pushed |
Everything else Git does happens without a network.
git clone: once per project
$ git clone https://gitlab.com/northwind-trails/trailguide.gitCloning into 'trailguide'...
done.Over a network you also see remote: Enumerating objects… and Receiving objects: 100%. What you get: a folder, the whole history in .git, origin configured, and the default branch checked out (lesson 4.1).
git remote: the configuration
remote touches no commits; it manages the list of URLs.
| Command | Effect |
|---|---|
git remote -v |
List remotes and their URLs |
git remote show origin |
Ask the server for the full picture, including which branches are tracked |
git remote add <name> <url> |
Add one, typically origin on a folder made with git init |
git remote set-url origin <url> |
Repoint an existing remote, for example HTTPS to SSH |
git remote rename <old> <new> |
Rename |
git remote remove <name> |
Forget one; commits are untouched |
$ git remote -vorigin https://gitlab.com/northwind-trails/trailguide.git (fetch)
origin https://gitlab.com/northwind-trails/trailguide.git (push)git fetch: look without touching
$ git fetchFrom https://gitlab.com/northwind-trails/trailguide
6050e19..f75f2fe main -> origin/mainRead the last line as "the remote's main moved from 6050e19 to f75f2fe, and I have updated your bookmark origin/main to match". Your own main did not move and no file changed. Silence means there was nothing new.
Now git status can tell you where you stand:
$ git status -sb## main...origin/main [behind 1]And you can read the incoming work before accepting it:
$ git log --oneline main..origin/mainf75f2fe docs: link FAQ from READMEgit pull: fetch, then integrate
git pull is git fetch followed by a merge (or a rebase, if you configured that). When you have no commits of your own, the merge is a fast-forward:
$ git pullUpdating 216f956..01268bf
Fast-forward
docs/faq.md | 4 ++++
1 file changed, 4 insertions(+)When both sides have commits, it makes a merge commit:
$ git pullMerge made by the 'ort' strategy.
data/trails.csv | 1 +
docs/faq.md | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)Because pull changes your files, it refuses when uncommitted work would be overwritten:
error: Your local changes to the following files would be overwritten by merge:
README.md
Please commit your changes or stash them before you merge.
AbortingCommit or stash first, then pull again. Lesson 7.5 compares fetch and pull properly.
git push: send your commits
$ git pushTo https://gitlab.com/you/trailguide.git
01268bf..127f39e main -> mainThe range 01268bf..127f39e is what the remote's branch moved through. A brand-new branch prints * [new branch] instead and needs -u the first time (lesson 6.4).
Push sends commits, never uncommitted or staged changes. If a colleague pushed first, your push is refused; that is lesson 7.6.
How to do it
The daily rhythm:
$ git pull
$ git pushPull when you start and before you push; push whenever a piece of work is done. Use git fetch plus git status when you want to know what is coming without accepting it yet.
- The sync button in the status bar shows two arrows with the ahead and behind counts. Clicking it runs pull then push.
- For one direction only: … menu → Pull, or … menu → Push.
- … menu → Fetch updates the counts without changing files. Turn on Git: Autofetch in Settings and VS Code does this in the background.
- The Command Palette has all of them: Git: Fetch, Git: Pull, Git: Push, Git: Clone.
- Update Project (Ctrl+T / ⌘T) is pull; its dialog chooses merge or rebase.
- Git → Push (Ctrl+Shift+K / ⇧⌘K) shows exactly which commits will be sent before you confirm, which is a good habit.
- Git → Fetch updates the bookmarks silently; the branches popup then shows the incoming counts.
- Git → Manage Remotes… is the equivalent of
git remote.
The remote is what you are looking at: every push appears under Code → Commits within seconds, and the pipeline starts. The Code button in the upper-right corner gives the clone URLs (Clone with SSH, Clone with HTTPS) and an Open in your IDE section for Visual Studio Code and IntelliJ IDEA.
GitLab has no equivalent of fetch or pull: those are how your computer catches up with what you see on the page.
Same: pushes appear under the repository's commit list, and the Code button above the file list holds the HTTPS, SSH and GitHub CLI URLs plus Open with GitHub Desktop.
The web interface shows the result of pushes; it cannot fetch or pull on your behalf.
Common mistakes
- "I committed but my colleague cannot see it." Committing is local; push.
- "I pulled and my work disappeared." Almost always the work was on another branch, or was never committed.
git status,git log --oneline --all --graphand the reflog find it. - Pulling with a dirty working tree. Git refuses and names the files; commit or stash.
- Adding a second remote instead of repointing.
git remote set-url, not a secondadd. - Expecting
git pushto send uncommitted changes. It sends commits only.
Try it yourself
Goal: run all four commands and watch which parts of the repository each one touches.
- In the playground with a remote configured, run
git remote -vandgit remote show origin. - Make a change on the website (edit
docs/faq.mdin the browser and commit it there). - Run
git fetch, thengit status -sb, thengit log --oneline main..origin/main. Confirm that your local file has not changed. - Run
git pulland confirm the file has now changed. - Make a local commit and
git push; read the range in the output.
Expected result: after step 3 the status says [behind 1] and the file on disk is unchanged; after step 4 it is up to date and the file has the new text.
Show solution
Step 3 is the whole point of the lesson: fetch moved only the bookmark, so Git knew about the change while your files stayed as they were. That is what makes fetch safe to run at any moment, even mid-edit, and why lesson 7.5 recommends it as the habit.