Git basics

Clone a repository

Download your own copy of a project from GitHub or GitLab, with its full history, so you can work on it.

Fill these in once
  1. Go to the folder where the project should live
    Terminal
    cd ~/Documents
  2. Clone the repository
    Terminal
    git clone https://github.com/user/project.git

    Copy the address from the green Code button on GitHub. If you set up an SSH key, use the SSH address instead of the https one.

  3. Private repository? Clone with a token instead
    Terminal
    git clone https://ghp_yourtoken@github.com/user/project.git

    Use this in place of the step above. Make a personal access token on GitHub under Settings, then Developer settings, and give it access to this repository.

  4. Then take the token out of the saved address
    Terminal
    git -C project remote set-url origin https://github.com/user/project.git

    Otherwise the token sits in the project's settings in plain text. When Git asks for a password later, paste the token.

  5. Step into the new folder
    Terminal
    cd project

    Git names the folder after the project. To pick your own name, add it at the end of the clone command.

Check it worked

  1. Check where it came from
    Terminal
    git remote -v

    You should see the address you cloned from, labelled origin.

  2. See the latest history
    Terminal
    git log --oneline -5
Undo it
  1. Delete the copy
    Terminal
    cd .. && rm -rf project

    This only removes your copy on this computer. The project online is not touched.

  1. Go to the folder where the project should live
    Terminal · Ubuntu / Debian
    cd ~
  2. Clone the repository
    Terminal · Ubuntu / Debian
    git clone https://github.com/user/project.git

    Copy the address from the green Code button on GitHub. If you set up an SSH key, use the SSH address instead of the https one.

  3. Private repository? Clone with a token instead
    Terminal · Ubuntu / Debian
    git clone https://ghp_yourtoken@github.com/user/project.git

    Use this in place of the step above. Make a personal access token on GitHub under Settings, then Developer settings, and give it access to this repository.

  4. Then take the token out of the saved address
    Terminal · Ubuntu / Debian
    git -C project remote set-url origin https://github.com/user/project.git

    Otherwise the token sits in the project's settings in plain text. When Git asks for a password later, paste the token.

  5. Step into the new folder
    Terminal · Ubuntu / Debian
    cd project

    Git names the folder after the project. To pick your own name, add it at the end of the clone command.

Check it worked

  1. Check where it came from
    Terminal · Ubuntu / Debian
    git remote -v

    You should see the address you cloned from, labelled origin.

  2. See the latest history
    Terminal · Ubuntu / Debian
    git log --oneline -5
Undo it
  1. Delete the copy
    Terminal · Ubuntu / Debian
    cd .. && rm -rf project

    This only removes your copy on this computer. The project online is not touched.

  1. Go to the folder where the project should live
    PowerShell
    cd $HOME\Documents
  2. Clone the repository
    PowerShell
    git clone https://github.com/user/project.git

    Copy the address from the green Code button on GitHub. If you set up an SSH key, use the SSH address instead of the https one.

  3. Private repository? Clone with a token instead
    PowerShell
    git clone https://ghp_yourtoken@github.com/user/project.git

    Use this in place of the step above. Make a personal access token on GitHub under Settings, then Developer settings, and give it access to this repository.

  4. Then take the token out of the saved address
    PowerShell
    git -C project remote set-url origin https://github.com/user/project.git

    Otherwise the token sits in the project's settings in plain text. When Git asks for a password later, paste the token.

  5. Step into the new folder
    PowerShell
    cd project

    Git names the folder after the project. To pick your own name, add it at the end of the clone command.

Check it worked

  1. Check where it came from
    PowerShell
    git remote -v

    You should see the address you cloned from, labelled origin.

  2. See the latest history
    PowerShell
    git log --oneline -5
Undo it
  1. Delete the copy
    PowerShell
    cd ..; Remove-Item -Recurse -Force project

    This only removes your copy on this computer. The project online is not touched.

New to Clone? I explain it in plain English on Layman Terms.