If a repository already exists on GitHub, the usual starting point is not git init. It is git clone.
git clone copies a remote repository locally
To create a local copy of an existing GitHub repository:
git clone https://github.com/OWNER/REPO.git
This gives you:
- a local working copy of the repository
- the Git history
- a configured remote named
origin
Cloning with SSH
If you use SSH authentication, clone with the SSH URL:
git clone git@github.com:OWNER/REPO.git
This sets up the remote to use SSH for all future pushes and pulls, avoiding credential prompts.
git fetch downloads remote updates without changing your current branch
To bring down remote information without integrating it into your current work yet:
git fetch
This is useful when you want to inspect what changed before updating your current branch.
git pull fetches and then updates the current branch
To download remote changes and integrate them into the current branch:
git pull
This is often the quick everyday sync command, but it helps to understand what it combines.
In broad terms:
git fetchgets the new remote informationgit pullfetches and then updates the current branch
git pull --rebase keeps history linear
By default, git pull merges remote changes, which can create extra merge commits. Using --rebase replays your local commits on top of the fetched changes instead:
git pull --rebase
This produces a cleaner, linear history. You can configure Git to use rebase by default for all pulls:
git config --global pull.rebase true
Rebasing during a pull is safe as long as your local commits have not been pushed yet.
When to use clone, fetch, and pull
Use:
git clonewhen you are getting the repository for the first timegit fetchwhen you want the latest remote information without immediately updating your branchgit pullwhen you want to bring the current branch up to date
A practical default
For beginner workflows:
- clone the repository once
- pull before starting a new piece of work
- fetch when you want a more cautious view of remote changes first
That default is simple and safe enough for most day-to-day use.