> For the complete documentation index, see [llms.txt](https://learn.sitecove.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.sitecove.com/how-to-guides/website-design-and-development/web-hosting-and-deployment/setting-up-version-control.md).

# Setting Up Version Control

Version control is a critical aspect of modern software development, allowing developers to track changes, collaborate efficiently, and manage the history of a project. **Git** is one of the most widely used version control systems, and it is often paired with platforms like **GitHub** and **GitLab** to host repositories and collaborate on projects. In this article, we’ll explore how to set up version control using Git and connect it to GitHub or GitLab, providing you with a powerful workflow for managing your project’s source code.

***

#### **What is Version Control?**

Version control refers to the practice of tracking and managing changes to software code. This system allows developers to work on projects collaboratively while maintaining a history of all changes made. If any issues arise, developers can roll back to previous versions of their code, compare different versions, and merge changes made by different contributors.

**Git** is a distributed version control system that enables developers to keep track of changes to files locally and collaborate with others using remote repositories hosted on platforms like **GitHub** and **GitLab**.

***

#### **Setting Up Git Locally**

Before you can start using Git for version control, you need to set it up on your local machine.

**1. Install Git**

To get started with Git, you’ll first need to install it on your local machine.

* **Windows**: Download the Git installer from the [official Git website](https://git-scm.com/), then run the installation file and follow the instructions.
* **macOS**: You can install Git using Homebrew by running `brew install git` in the terminal, or you can download the installer from the Git website.
* **Linux**: Most Linux distributions come with Git pre-installed. If not, you can install it via your package manager, for example, `sudo apt install git` on Ubuntu.

**2. Configure Git**

After installing Git, you need to configure your user name and email address, which will be associated with your commits.

Open the terminal and run the following commands:

```bash
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
```

These settings are saved globally, so you don’t need to configure them again for each repository.

**3. Initialize a Git Repository**

Once Git is installed and configured, you can start tracking changes in a project by initializing a Git repository. In your project directory, open the terminal and run:

```bash
git init
```

This command creates a `.git` directory in your project, which is used by Git to track changes.

***

#### **Setting Up a Remote Repository (GitHub or GitLab)**

To collaborate with others or back up your code online, you'll need to use a remote Git repository. **GitHub** and **GitLab** are two popular platforms for hosting Git repositories. Here, we'll cover the basics of setting up a repository on both platforms.

**1. Create a GitHub or GitLab Account**

First, sign up for a free account on either [GitHub](https://github.com/) or [GitLab](https://gitlab.com/), depending on your preference.

**2. Create a New Repository**

* **GitHub**:
  1. After logging in, click on the "+" icon in the top-right corner of the GitHub homepage and select **New repository**.
  2. Name your repository, add a description, and choose whether to make it public or private.
  3. You can initialize the repository with a `README.md` file, but if you already have a local project, you can skip this.
* **GitLab**:
  1. Log into your GitLab account and click on the **New project** button.
  2. Choose a project name, and optionally, a description and visibility level.
  3. Click **Create project** to finish.

**3. Connect Your Local Repository to the Remote Repository**

Once your remote repository is created, you need to connect your local Git repository to it. Copy the URL of your repository from GitHub or GitLab (it should look like `https://github.com/username/repository-name.git` or `https://gitlab.com/username/repository-name.git`).

In the terminal, navigate to your local project directory and run:

```bash
git remote add origin https://github.com/username/repository-name.git
```

This command links your local repository to the remote one, allowing you to push changes to GitHub or GitLab.

**4. Push Your Local Files to the Remote Repository**

Now that your local and remote repositories are connected, you can upload your code. Start by adding your files to Git’s staging area:

```bash
git add .
```

This command stages all files in the project directory for commit. Next, commit your changes:

```bash
git commit -m "Initial commit"
```

This records the changes in your local Git repository. Finally, push your changes to the remote repository:

```bash
git push -u origin master
```

The `-u` flag sets the remote repository as the default for future pushes, so you only need to run `git push` next time.

***

#### **Working with Git (GitHub/GitLab) Locally and Remotely**

Once your repository is set up, you can begin using Git to manage your project. Here are some common tasks you’ll use while working with Git.

**1. Cloning a Repository**

If you want to work on an existing repository, you can **clone** it to your local machine. Run:

```bash
git clone https://github.com/username/repository-name.git
```

This command copies the entire repository (including all its history) to your local machine, allowing you to work with the project files.

**2. Pulling Changes from the Remote Repository**

When others have made changes to the project or you need to update your local repository with the latest changes, you can use the **git pull** command:

```bash
git pull origin master
```

This fetches and merges changes from the remote repository to your local copy.

**3. Branching and Merging**

For collaboration, you may want to work on features or bug fixes without affecting the main codebase. This is done through **branches**.

To create a new branch:

```bash
git checkout -b new-feature
```

This creates and switches to the new branch. After making changes, you can commit them:

```bash
git add .
git commit -m "Added a new feature"
```

Then, push your branch to the remote repository:

```bash
git push origin new-feature
```

To merge a branch into the master branch, first, switch to the master branch:

```bash
git checkout master
```

Then, merge the feature branch:

```bash
git merge new-feature
```

***

Version control is essential for modern web development, and Git is the most powerful tool available for managing your project’s source code. By setting up Git locally and connecting it to platforms like GitHub or GitLab, you can easily track changes, collaborate with other developers, and maintain a clean history of your project.&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.sitecove.com/how-to-guides/website-design-and-development/web-hosting-and-deployment/setting-up-version-control.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
