Remotes and GitHub

Clone a repository

Download a remote repository, its branches, and its history into a new local folder.

8 minute lesson

~~~

Cloning creates a new local repository from an existing one.

Run:

git clone [email protected]:flaviocopes/notes.git

Git creates a notes folder, copies reachable repository data, configures the source as origin, and checks out the remote’s default branch as a local branch.

Move into the repository and inspect the state:

cd notes
git status
git remote -v
git branch --all

The working tree contains one checked-out branch. Other remote branches usually appear as remote-tracking references such as origin/add-search; Git does not create a local branch for every one.

A clone is independent. New local commits do not change the source repository until you push and have permission to do so.

If cloning stops midway, remove only the incomplete destination folder after confirming its exact path, then retry. Do not run git init inside the partial clone and hope it repairs missing objects.

Exercise: clone a small repository, disconnect from the network, and run git log. Explain why the history remains available.

Lesson completed

Take this course offline

Get every free book, course edition, and software download.

Get the download library →