You don't need a GitLab account to use Git locally, but for the purpose of this guide we
To start using GitLab with Git, complete the following tasks:
recommend registering and signing into your account before starting. Some commands need a
connection between the files on your computer and their version on a remote server.
You must also open a [terminal](#open-a-terminal) and have
- Create and sign in to a GitLab account.
[Git installed](#install-git) on your computer.
-[Open a terminal](#open-a-terminal).
-[Install Git](#install-git) on your computer.
-[Configure Git](#configure-git).
-[Choose a repository](#choose-a-repository).
### Open a terminal
### Open a terminal
To execute Git commands on your computer, you must open a terminal (also known as command
To execute Git commands on your computer, you must open a terminal (also known as command
prompt, command shell, and command line) of your preference. Here are some suggestions:
prompt, command shell, and command line). Here are some options:
- For macOS users:
- For macOS users:
- Built-in: [Terminal](https://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line). Press <kbd>⌘ command</kbd> + <kbd>space</kbd> and type "terminal" to find it.
- Built-in[Terminal](https://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line). Press <kbd>⌘ command</kbd> + <kbd>space</kbd> and type `terminal`.
-[iTerm2](https://iterm2.com/), which you can integrate with [zsh](https://git-scm.com/book/id/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Zsh) and [oh my zsh](https://ohmyz.sh/) for color highlighting, among other handy features for Git users.
-[iTerm2](https://iterm2.com/). You can integrate it with [zsh](https://git-scm.com/book/id/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Zsh) and [oh my zsh](https://ohmyz.sh/) for color highlighting and other advanced features.
- For Windows users:
- For Windows users:
- Built-in: `cmd`. Click the search icon on the bottom navigation bar on Windows and type `cmd` to find it.
- Built-in command line. On the Windows taskbar, select the search icon and type `cmd`.
-[PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/install/installing-windows-powershell?view=powershell-7): a Windows "powered up" shell, from which you can execute a greater number of commands.
To connect your computer with GitLab, you need to add your credentials to identify yourself.
You have two options:
- Authenticate on a project-by-project basis through HTTPS, and enter your credentials every time
you perform an operation between your computer and GitLab.
- Authenticate through SSH once and GitLab no longer requests your credentials every time you
perform an operation between your computer and GitLab.
To start the authentication process, we'll [clone](#clone-a-repository) an existing repository
to our computer:
- If you want to use **SSH** to authenticate, follow the instructions on the [SSH documentation](../ssh/README.md)
to set it up before cloning.
- If you want to use **HTTPS**, GitLab requests your username and password:
- If you have 2FA enabled for your account, you must use a [Personal Access Token](../user/profile/personal_access_tokens.md)
with **read_repository** or **write_repository** permissions instead of your account's password.
- If you don't have 2FA enabled, use your account's password.
NOTE:
Authenticating through SSH is the GitLab recommended method. You can read more about credential storage
in the [Git Credentials documentation](https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage).
## Git terminology
If you're familiar with Git terminology, you may want to jump directly
into [setting up a repository](#set-up-a-repository).
### Repository
Your files in GitLab live in a **repository**, similar to how you have them in a folder or
directory on your computer.
-**Remote** repository refers to the files in GitLab.
Before you begin, choose the repository you want to work in. You can use any project you have permission to
- A **local** copy refers to the files on your computer.
access on GitLab.com or any other GitLab instance.
<!-- vale gitlab.Spelling = NO -->
To use the repository in the examples on this page:
<!-- vale gitlab.SubstitutionWarning = NO -->
Often, the word "repository" is shortened to "repo".
<!-- vale gitlab.Spelling = YES -->
<!-- vale gitlab.SubstitutionWarning = YES -->
A **project** in GitLab is what holds a repository.
1. Go to [https://gitlab.com/gitlab-tests/sample-project/](https://gitlab.com/gitlab-tests/sample-project/).
1. In the top right, select **Fork**.
1. Choose a namespace for your fork.
### Fork
The project becomes available at `https://gitlab.com/<your-namespace>/sample-project/`.
When you want to copy someone else's repository, you [**fork**](../user/project/repository/forking_workflow.md#creating-a-fork)
You can [fork](../user/project/repository/forking_workflow.md#creating-a-fork) any project you have access to.
the project. By forking it, you create a copy of the project into your own
[namespace](../user/group/#namespaces) to have read and write permissions to modify the project files
and settings.
For example, if you fork this project, <https://gitlab.com/gitlab-tests/sample-project/> into your namespace,
## Clone a repository
you create your own copy of the repository in your namespace (`https://gitlab.com/your-namespace/sample-project/`).
From there, you can clone the repository, work on the files, and (optionally) submit proposed changes back to the
original repository.
### Difference between download and clone
When you clone a repository, the files from the remote repository are downloaded to your computer,
and a connection is created.
To create a copy of a remote repository's files on your computer, you can either
This connection requires you to add credentials. You can either use SSH or HTTPS. SSH is recommended.
**download** or **clone** the repository. If you download it, you cannot sync the repository with the
remote version on GitLab.
[Cloning](#clone-a-repository) a repository is the same as downloading, except it preserves the Git connection
### Clone with SSH
with the remote repository. This allows you to modify the files locally and
upload the changes to the remote repository on GitLab.
### Pull and push
Clone with SSH when you want to authenticate only one time.
After you save a local copy of a repository and modify the files on your computer, you can upload the
1. Authenticate with GitLab by following the instructions in the [SSH documentation](../ssh/README.md).
changes to GitLab. This is referred to as **pushing** to the remote, as this is achieved by the command
1. Go to your project's landing page and select **Clone**. Copy the URL for **Clone with SSH**.
[`git push`](#send-changes-to-gitlabcom).
1. Open a terminal and go to the directory where you want to clone the files. Git automatically creates a folder with the repository name and downloads the files there.
1. Run this command:
When the remote repository changes, your local copy is behind. You can update your local copy with the new
Remember to replace the example URLs with the relevant path of your project.
To get started, choose one of the following:
- Use the example project by signing into GitLab.com and [forking](../user/project/repository/forking_workflow.md#creating-a-fork)
it into your namespace to make it available under `https://gitlab.com/<your-namespace>/sample-project/`.
- Copy an existing GitLab repository onto your computer by [cloning a repository](#clone-a-repository).
- Upload an existing folder from your computer to GitLab by [converting a local folder into a Git repository](#convert-a-local-directory-into-a-repository).
### Clone a repository
1. To view the files, go to the new directory:
To start working locally on an existing remote repository, clone it with the
```shell
command `git clone <repository path>`. You can either clone it using [HTTPS](#clone-using-https)
cd sample-project
or [SSH](#clone-using-ssh), according to your preferred [authentication method](#git-authentication-methods).
```
You can find both paths (HTTPS and SSH) by navigating to your project's landing page
You can also
and clicking **Clone**. GitLab prompts you with both paths, from which you can copy
[clone a repository and open it directly in Visual Studio Code](../user/project/repository/index.md#clone-and-open-in-visual-studio-code).
and paste in your command line. You can also
[clone and open directly in Visual Studio Code](../user/project/repository/index.md#clone-and-open-in-apple-xcode).
For example, with our [sample project](https://gitlab.com/gitlab-tests/sample-project/):
### Clone with HTTPS
- To clone through HTTPS, use `https://gitlab.com/gitlab-tests/sample-project.git`.
Clone with HTTPS when you want to authenticate each time you perform an operation
- To clone through SSH, use `git@gitlab.com:gitlab-tests/sample-project.git`.
between your computer and GitLab.
To get started, open a terminal window in the directory you wish to add the
1. Go to your project's landing page and select **Clone**. Copy the URL for **Clone with HTTPS**.
repository files into, and run one of the `git clone` commands as described below.
1. Open a terminal and go to the directory where you want to clone the files.
1. Run the following command. Git automatically creates a folder with the repository name and downloads the files there.
Both commands download a copy of the files in a folder named after the project's
```shell
name and preserve the connection with the remote repository.