32  32. Cloning and Pulling (Working from Two Computers)

Once your repository is on GitHub, you can get a copy of it on any computer with git clone, and keep the copies in sync with git push and git pull. This page is about one person (you) using two computers, for example your laptop and a computer-lab PC, or making a quick edit on github.com. Working with other people is covered later, in Sharing a Repository: Collaborators and Forks.

   LAPTOP                 GITHUB                 LAB PC
           --- push --->           --- pull --->
           <--- pull ---           <--- push ---

GitHub is the meeting point: each computer pushes its new commits there and pulls the other computer’s commits from there.

32.1 git clone: copy a repository to a computer

In the examples, Maria pushed her practice project to GitHub on the previous page. Now she is at a Windows PC in the computer lab, using Git Bash. First she copies the repository’s URL from GitHub: on the repository’s page, she clicks the Code button and copies the HTTPS URL. Then:

mkdir -p ~/projects
cd ~/projects
git clone https://github.com/YOUR-USERNAME/git-tutorial-project.git

(mkdir -p creates the projects folder if it doesn’t exist yet, and does nothing if it does.)

Output:

Cloning into 'git-tutorial-project'...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 24 (delta 5), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (24/24), done.
Resolving deltas: 100% (5/5), done.

git clone:

  • creates a new folder named after the repository (git-tutorial-project),
  • downloads all the files and the complete history,
  • remembers where the copy came from, as a remote named origin, and connects the local main branch to origin/main,
  • so you do not run git init or git remote add in a cloned folder.
cd git-tutorial-project
git log --oneline

Output:

736e88f (HEAD -> main, origin/main, origin/HEAD) Ignore .env and add .env.example template
fc2bb9b Revert "Make heading navy"
cb793da Make heading navy
4293e1d Add intro and contact email to home page
b90f840 Describe planned pages in README
ffd1f1f Add starter files for portfolio site

The same six commits, with the same IDs, as on her laptop. Two things are not in the clone, because they were never committed: the ignored .env file and the empty docs/ folder. Maria re-creates .env from the template (see .gitignore and Keeping Secrets Out of Git):

cp .env.example .env

and then types her real key into .env with a text editor.

A few more facts about cloning:

  • Each computer needs Git installed and configured (Installing and Configuring Git). To clone a private repository or to push, you must also be signed in to GitHub on that computer (Putting Your Repository on GitHub). On a shared lab computer, don’t leave your login saved: if you signed in with the GitHub CLI, gh auth logout removes it when you’re done. If Git Credential Manager signed you in (the Windows default), open Windows’ Credential Manager, choose Windows Credentials, and remove the entry git:https://github.com.
  • Anyone can clone a public repository without signing in. For example, GitHub’s practice repository: git clone https://github.com/octocat/Spoon-Knife.git. You can change your copy, but you can’t push to someone else’s repository.
  • To use a different folder name, add it at the end: git clone https://github.com/YOUR-USERNAME/git-tutorial-project.git portfolio.
  • Clone into a normal folder such as ~/projects (one that Dropbox, OneDrive or iCloud doesn’t sync; see Your First Repository), not inside another repository.

32.2 Push from the second computer

At the lab PC, Maria adds a status line to the README and commits it, exactly as on her laptop:

echo "Status: home page done, contact page next." >> README.md
git add README.md
git commit -m "Add project status to README"
git status

Output (of git status):

On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

“Ahead by 1 commit” means this computer has a commit that GitHub doesn’t have yet. Because git clone connected main to origin/main, a plain git push is enough:

git push

Output:

Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 340 bytes | 340.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
To https://github.com/YOUR-USERNAME/git-tutorial-project.git
   736e88f..647a9b5  main -> main

The last line says GitHub’s main moved from commit 736e88f to 647a9b5.

32.3 git pull: bring your copy up to date

Back home, Maria opens her laptop. Watch out: git status there still says Your branch is up to date with 'origin/main'. That message only reflects what the laptop knew the last time it talked to GitHub; it doesn’t check GitHub. To actually get the new commit:

git pull

Output:

remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (3/3), 320 bytes | 320.00 KiB/s, done.
From https://github.com/YOUR-USERNAME/git-tutorial-project
   736e88f..647a9b5  main       -> origin/main
Updating 736e88f..647a9b5
Fast-forward
 README.md | 1 +
 1 file changed, 1 insertion(+)

git pull downloads the new commits from GitHub and adds them to your branch. Fast-forward means the laptop had no new commits of its own, so Git simply moved main forward to include the downloaded ones; there was nothing to combine.

Edits you make on github.com (for example, editing README.md in the browser) are ordinary commits on GitHub. You bring them to your computer the same way, with git pull.

32.4 The daily routine

1. git pull                     <- start: get the latest version
2. edit files                   <- (by hand, or with an AI agent)
3. git status  /  git diff      <- review what changed
4. git add <files>
5. git commit -m "..."
6. git push                     <- finish: upload it for your other computer

A rule of thumb: pull when you sit down, push when you get up.

32.5 If you forget to pull: the push is rejected

One evening Maria fixed the README title on github.com. Later, on her laptop, she changed css/style.css and committed it without pulling first. Now GitHub and her laptop each have a commit the other one doesn’t have:

git push

Output:

To https://github.com/YOUR-USERNAME/git-tutorial-project.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/YOUR-USERNAME/git-tutorial-project.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Nothing is broken. Git refuses to push because that would throw away the commit on GitHub. The fix is the hint’s advice: pull, then push.

git pull

Because both sides have new commits, git pull creates a merge commit that combines them. Git opens your text editor with a ready-made message (Merge branch 'main' of https://github.com/...); just save and close it (in nano: Ctrl+O, Enter, Ctrl+X). The output ends with:

Merge made by the 'ort' strategy.
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Now git push works, and GitHub has both changes.

“fatal: Need to specify how to reconcile divergent branches”

If git pull stops with this message (after several hint: lines), Git doesn’t know whether to merge or do something else. Set the beginner-friendly default once (see Installing and Configuring Git), then pull again:

git config --global pull.rebase false
git pull

Two other things can stop a pull:

  • Uncommitted changes to the same files. Git prints error: Your local changes to the following files would be overwritten by merge: and does nothing. Commit your changes (or discard them with git restore), then pull again.
  • The same lines were changed on both computers. Git can’t decide which version to keep and reports a merge conflict, which you resolve by hand. See Merge Conflicts. Pulling before you start work is the best way to avoid conflicts.

git log --oneline --graph draws the history as a graph. After the merge above, Maria’s laptop shows:

*   c0d14e5 (HEAD -> main) Merge branch 'main' of https://github.com/YOUR-USERNAME/git-tutorial-project
|\
| * 0b2c2b7 (origin/main) Update README.md
* | b25b21a Increase line spacing
|/
* 647a9b5 Add project status to README

The two lines of work split after 647a9b5 (the web edit on one side, the laptop’s CSS commit on the other) and come back together in the merge commit. After git push, origin/main points to the merge commit too.

Don’t use Dropbox or OneDrive instead of push and pull

It’s tempting to keep the repository in a Dropbox, OneDrive, iCloud or Google Drive folder, so that it “just appears” on your other computer. Don’t. The sync service copies the hidden .git folder one file at a time, and when both computers change it, you get “conflicted copy” files or a broken repository. It also uploads your .env files with their secret keys, which .gitignore keeps out of GitHub but not out of Dropbox. Push and pull are the safe way to move your work, and every commit you push is already backed up on GitHub. (See “Where to keep your projects” in Your First Repository.)

32.6 Forking vs. cloning

Cloning copies a repository to your computer. You can clone any public repository, but you can push only to repositories you own or have been given access to. A fork is a copy of someone else’s repository made on GitHub, in your own account (using the Fork button). Because the fork belongs to you, you can clone it and push to it. People fork projects to build their own version or to propose changes to the original. The full-stack tutorial starts this way (Fork the repo and clone it), and Sharing a Repository: Collaborators and Forks explains forks in detail.

Practice Questions

Easy

Question 1 · Multiple choice

What does git clone https://github.com/YOUR-USERNAME/git-tutorial-project.git do?

  1. Uploads your local project to GitHub
  2. Creates a folder git-tutorial-project with all the files and the full history, and sets up origin
  3. Copies only the latest version of the files, without history
  4. Creates an empty repository on GitHub

b. Cloning downloads the files and the complete history into a new folder and remembers the URL as the remote origin. Uploading is git push (a). A clone always includes the history (c). Creating a repository on GitHub (d) happens on github.com (or with gh repo create).

Question 2 · True or false

After cloning a repository, you need to run git init and git remote add origin ... in the new folder.

False. The cloned folder is already a repository, and origin is already set to the URL you cloned from. Check with git remote -v.

Question 3 · Short answer

In one sentence, what does git pull do?

It downloads the commits that are on GitHub (the remote) but not yet on your computer, and adds them to your current branch.

Question 4 · Matching

Match each term with its meaning.

Term Meaning
1. git clone A. upload your new commits to GitHub
2. git pull B. the usual name for the remote your copy came from
3. git push C. download a repository (files and history) for the first time
4. origin D. a copy of someone else’s repository in your own GitHub account
5. fork E. get new commits from GitHub into your existing copy

1 → C, 2 → E, 3 → A, 4 → B, 5 → D.

Question 5 · Fill in the blank

Rule of thumb for working from two computers: “________ when you sit down, ________ when you get up.”

“Pull when you sit down, push when you get up.” Start each session with git pull and end it with git push, so the next computer you use can pull your work.

Question 6 · True or false

You can clone a public GitHub repository without signing in to GitHub.

True. Public repositories can be cloned by anyone. You need to sign in to clone a private repository, and to push.

Medium

Question 7 · Write the command

Write the command that clones https://github.com/YOUR-USERNAME/git-tutorial-project.git into a folder named portfolio instead of the default name.

git clone https://github.com/YOUR-USERNAME/git-tutorial-project.git portfolio

Question 8 · Read the output

What does this git status output mean, and what should Maria do next?

On branch main
Your branch is ahead of 'origin/main' by 2 commits.
  (use "git push" to publish your local commits)

Her computer has two commits that GitHub doesn’t have yet. She should run git push to upload them, so her other computer can pull them later.

Question 9 · Ordering

Put the daily routine in order:

  • A. git push
  • B. edit files
  • C. git pull
  • D. git commit -m "..."
  • E. git status and git diff
  • F. git add <files>

C → B → E → F → D → A: pull, edit, review, stage, commit, push.

Question 10 · Short answer

Maria pushed a commit from the lab PC an hour ago. On her laptop, git status says Your branch is up to date with 'origin/main'. Is the laptop really up to date? Explain.

No. git status doesn’t contact GitHub; it compares with what the laptop learned the last time it talked to GitHub, which was before the lab-PC push. git pull downloads the new commit and actually brings the laptop up to date.

Question 11 · Find the bug

Sam runs git clone https://github.com/YOUR-USERNAME/git-tutorial-project.git in his projects folder and gets:

fatal: destination path 'git-tutorial-project' already exists and is not an empty directory.

What does this mean, and what are his options?

A folder named git-tutorial-project already exists there (probably an earlier clone or the unzipped practice files). Options:

  • If it’s already a clone of this repository, don’t clone again: cd into it and run git pull.
  • Clone into a different folder name: git clone https://github.com/YOUR-USERNAME/git-tutorial-project.git portfolio.
  • Clone from a different location (another parent folder).

Question 12 · Read the output

The output of git pull contains the word Fast-forward. What does that tell you?

Your computer had no new commits of its own, so Git only had to move your main branch forward to include the downloaded commits. Nothing needed to be combined, so no merge commit was created.

Question 13 · Scenario

Maria clones her repository on the lab PC and runs git remote -v. What does she see, and why didn’t she have to add the remote herself?

origin  https://github.com/YOUR-USERNAME/git-tutorial-project.git (fetch)
origin  https://github.com/YOUR-USERNAME/git-tutorial-project.git (push)

git clone automatically records the URL it cloned from as the remote named origin, used for both fetching (pulling) and pushing.

Hard

Question 14 · Scenario

Maria edited the README on github.com, then (without pulling) committed a CSS change on her laptop. git push prints ! [rejected] main -> main (fetch first). Explain why the push was rejected, and list the commands to fix it. What happens during the fix?

GitHub has a commit (the web edit) that her laptop doesn’t have. Pushing would replace GitHub’s history and lose that commit, so Git refuses. Fix:

git pull
git push

git pull downloads the web edit and, because both sides have new commits, creates a merge commit that combines them (Git opens the editor with a ready-made message: save and close). Then git push succeeds. If both edits had changed the same lines, she would have to resolve a merge conflict first.

Question 15 · Find the bug

In the same situation, Sam’s git pull prints several hint: lines and ends with:

fatal: Need to specify how to reconcile divergent branches.

Why, and how does he fix it?

His Git has no setting that says how git pull should combine diverged branches (merge, rebase, or fast-forward only), so it refuses to guess. Set the merge behavior once and pull again:

git config --global pull.rebase false
git pull

(The Git for Windows installer normally sets this for you; it’s mostly Mac users who need this line.)

Question 16 · Scenario

Maria starts editing README.md on her laptop before pulling. When she runs git pull, Git prints error: Your local changes to the following files would be overwritten by merge: followed by README.md, and Aborting. What happened, and what can she do?

The commits she is pulling also change README.md, and Git won’t overwrite her uncommitted edits, so it stopped without changing anything. She can:

  • keep her edits: git add README.md and git commit, then git pull (which may create a merge commit, or a conflict if the same lines changed), then git push; or
  • throw her edits away: git restore README.md, then git pull.

Next time, pull before starting to edit.

Question 17 · Compare

Compare cloning and forking: where does the copy live, and can you push to it?

Clone Fork
Where the copy lives on your computer on GitHub, in your account
Made with git clone <url> the Fork button on github.com
Can you push? only if you own the original or were given access yes, it’s your repository

They are often used together: fork someone’s project on GitHub, then clone your fork to your computer.

Question 18 · Scenario

Maria clones a classmate’s public repository, improves the README, and commits. git push fails with a “permission denied” error. Why? What could she do instead?

Anyone can clone a public repository, but only the owner (and people they give access to) can push to it. She could fork the repository on GitHub and push to her fork, or ask the classmate to add her as a collaborator. Both are covered in Sharing a Repository: Collaborators and Forks.

Question 19 · Long answer

Maria works on her project from a laptop, a lab PC, and sometimes github.com. Describe a routine that keeps all copies in sync, and explain what can go wrong if she doesn’t follow it.

A good answer includes:

  • Start every session with git pull (on the computer she’s using).
  • Work in small commits: git status/git diff, git add, git commit.
  • End every session with git push, so the next computer can pull.
  • After editing on github.com, pull on each computer before working there.

What can go wrong: if she forgets to pull, her push is rejected and she must pull (creating a merge commit) before pushing. If she edits the same lines in two places without syncing, she gets a merge conflict. If she forgets to push, her other computer doesn’t have the latest work. And uncommitted edits can block a pull.

© 2025-2026 Y. Rosenthal. All rights reserved.