Git: Fetch a (existing) remote repository to local repository

Lets say that there is an existing repository that we should pull the files from.

mkdir local-repo
cd local-repo
git init
git remote add origin user@server:remote-repo
git pull origin master

What is done here is

  • git init Initializes the directory as a git repository (creates .git directory and add needed files)
  • git remote add name url adds a remote repository with a name (origin) and url (user@server:remote-repo)
  • git pull name branch pull the existing content from the given brach (master)

The main difference bewteen this and creating a new remote repository is that no files are added and no initial commit is being made – since there is content in the remote repository we are joining.