← Back to Articles         
Clone, Fetch, Pull & Push

Clone, Fetch, Pull & Push

Published on 03 Oct 2026     5 min read Git & GitHub
Basic Git Commands

Git Remote Operations

1. What is git clone?

git clone creates a local copy of an existing Git repository.

git clone https://github.com/user/project.git

It downloads the project files and repository history to your machine.

Remote Repository
       ↓ clone
Local Repository + Working Directory

Interview Answer: git clone copies an existing repository to the local machine, including its files and commit history.


2. What happens internally when you clone a repository?

When you run:

git clone https://github.com/user/project.git

Git roughly does the following:

  1. Creates a new local directory.
  2. Creates the local .git repository.
  3. Downloads commits, objects, and references from the remote.
  4. Creates remote-tracking references such as origin/main.
  5. Configures the remote as origin.
  6. Checks out the default branch and creates the working files.
  7. Sets the local branch to track its corresponding remote branch.
Remote Repo
    ↓
Download Git data
    ↓
Create Local Repo
    ↓
Configure origin
    ↓
Checkout default branch

Interview Answer: Cloning downloads the repository data, creates a local repository, configures the remote as origin, and checks out the default branch.


3. What is git fetch?

git fetch downloads new commits and branch information from the remote repository without integrating them into your current local branch.

git fetch origin

For example:

Before fetch:

Local main       A──B
Remote main      A──B──C──D

After fetch:

Local main       A──B
origin/main      A──B──C──D

Your working files remain unchanged.

Interview Answer: git fetch downloads the latest remote changes but does not automatically integrate them into my current branch.


4. What is git pull?

git pull downloads remote changes and integrates them into the current local branch.

git pull origin main

Conceptually:

git pull
   ↓
git fetch
   +
integrate changes

By default this often means fetch + merge, though Git can be configured or instructed to rebase instead.

Interview Answer: git pull retrieves remote changes and integrates them into the current local branch.


5. git fetch vs git pull

git fetch git pull
Downloads remote changes Downloads + integrates changes
Current branch is not changed Current branch can change
Good for reviewing first Good when you want to update directly
Safer for inspection May produce merge/rebase conflicts
fetch = Download
pull  = Download + Integrate

Interview Answer

git fetch only downloads remote changes, while git pull downloads and integrates those changes into the current branch.


6. What is git push?

git push sends your local commits to a remote repository.

git push origin main
Local Repository
      ↓ push
Remote Repository

In real projects, developers commonly push a feature branch and create a Pull Request.

git push origin feature/login

Interview Answer: git push publishes local commits to a remote repository such as GitHub or Azure Repos.


7. What happens when you execute git pull?

Suppose:

Local:   A──B
Remote:  A──B──C──D

When you execute:

git pull

Git:

  1. Contacts the configured remote.
  2. Fetches C and D.
  3. Updates the relevant remote-tracking branch.
  4. Integrates those changes into your current branch.
  5. Updates your working files.

Result:

Local:   A──B──C──D
Remote:  A──B──C──D

If local and remote changes conflict, Git may require you to resolve conflicts.

Interview Answer

git pull first fetches changes from the remote repository and then integrates them into the current local branch, using merge or rebase depending on configuration.


8. Why can git push be rejected?

A common reason is that the remote branch contains commits that your local branch does not have.

Example:

Local:   A──B──C
Remote:  A──B──D

Another developer has pushed D.

Your push may be rejected to prevent accidentally overwriting remote history.

You normally synchronize first:

git pull
# resolve conflicts if required
git push

Push can also be rejected because of branch protection, permissions, authentication, or repository policies.

Interview Answer

A push is commonly rejected when the remote branch has changes that are not present locally. I first synchronize the branch, resolve any conflicts, and then push again.


9. What should you do when your local branch is behind the remote branch?

First retrieve and integrate the latest remote changes:

git pull

Then:

git push

A more controlled approach is:

git fetch origin
git status
git pull

In some team workflows, you may use rebase:

git pull --rebase

Use the merge/rebase strategy defined by your team's Git workflow.

Interview Answer

If my local branch is behind the remote branch, I first fetch or pull the latest changes, resolve any conflicts if necessary, and then push my changes.


10. What is origin in Git?

origin is the conventional default name for the remote repository from which you cloned.

git clone https://github.com/user/project.git

Git typically creates:

origin → https://github.com/user/project.git

Check it using:

git remote -v

So:

git push origin main

means:

push
  ↓
remote named "origin"
  ↓
branch "main"

origin is just a remote name/alias. It is not a special server and can be renamed.

Interview Answer

origin is the conventional default name Git gives to the remote repository when we clone a repository.


11. What is an Upstream Branch?

An upstream branch is the remote-tracking branch that your local branch is configured to track.

Example:

Local Branch        Upstream
main        →       origin/main

feature/login →     origin/feature/login

Set it when pushing:

git push -u origin feature/login

Here -u sets:

feature/login
      ↓ tracks
origin/feature/login

After that, instead of:

git push origin feature/login
git pull origin feature/login

you can usually use:

git push
git pull

Interview Answer

An upstream branch is the remote-tracking branch associated with a local branch. It allows Git to know where to push changes and from where to pull changes by default.


Quick Revision

clone    → Copy an existing repository
fetch    → Download remote changes
pull     → Fetch + integrate
push     → Send local commits to remote
origin   → Default/conventional remote name
upstream → Remote-tracking branch associated with local branch
← Back to Articles