# Integrating Remote Repositories

&#x20;Now that we have started working on our local repository in [Getting Started](/orbital/git/fundamental-concepts/getting-started.md), we may want others to view the contents of our repositories. We may also want a layer of security against local machine crashes by storing our repositories somewhere else.&#x20;

This is where remote repositories and Github come into play.&#x20;

## Creating a Github repository

{% hint style="warning" %}
As per [Setting up Git and GitHub](/orbital/git/setup.md), you should already have setup Github and SSH. If not, please go to [Setting up Git and GitHub](/orbital/git/setup.md) to ensure that it everything works before proceeding as the remainder of the guide will be using Github.
{% endhint %}

You can visit the following link: <https://github.com/new> or simply use the Github UI to create a new repository:

<figure><img src="/files/vqoIKzNcSX9Xln7bGugv" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/AchxZYYQHdl0hz22IdxM" alt="" width="289"><figcaption></figcaption></figure>

Then, you should see the following page:

<figure><img src="/files/J1mh0BnNo7aJwwPhXEJe" alt=""><figcaption></figcaption></figure>

Some key details to take note of:

* Repository template: creates a project with some basic files already included (we won't use this)
* Repository name: any name you want to give your project, you can follow the same name as your local folder <mark style="background-color:green;">**(please fill this up)**</mark>
* Description: optional description about your project (optional)
* Visibility: public (publicly accessible and viewable) or private (only viewable to yourself and any [collaborators](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-access-to-your-personal-repositories/inviting-collaborators-to-a-personal-repository)) <mark style="background-color:green;">**(set it to public for now)**</mark>
* `README`: file that normally contains basic documentation about the project <mark style="background-color:red;">**(do not create one)**</mark>
* `.gitignore`: tells Git to ignore certain files (such as private files) <mark style="background-color:red;">**(do not create one)**</mark>
* `LICENSE`: specifies an open-source license (if any) <mark style="background-color:red;">**(do not create one)**</mark>

{% hint style="danger" %}
We do not create a `README` or `.gitignore` or `LICENSE` as we have existing files locally and we don't want to cause any problems when trying to move the local repository to Github.
{% endhint %}

Once done, you should see the following:

<figure><img src="/files/m2Z7iBBzjGTLCtBs4nOt" alt=""><figcaption></figcaption></figure>

## Connecting your local repository with the remote repository

Now, let's get your local repository to Github through the remote repository you just created.

{% hint style="info" %}
We will be following the instructions under the "...or push an existing repository from the command line" section of the Github repository.
{% endhint %}

### Adding a new remote

The local repository needs to know which remote repository it is going to be connected to. This is where the `git remote` command comes in handy.

It is used to manage remote repositories for your local repository.

In this instance, we want to add the remote repository you created to the local repository under the name `origin` (in fact, we can name it anything, `origin` is just the convention):

```
git remote add origin git@github.com:<github username>/<repository name>.git
```

### Retrieving a remote branch

Now that you have added the remote repository link to the local repository, you then need to retrieve the `main` branch from the remote repository (recall that the `main`  branch is the default branch).

This is done using&#x20;

```
git branch -M main
```

### Uploading local repository snapshots to remote repository

To upload all local snapshots to the remote repository, you will use `git push`.

```
git push -u origin main
```

{% hint style="info" %}
`-u` flag will set the "[upstream](https://web.archive.org/web/20200307113003/https://mislav.net/2010/07/git-tips/)" which refers to the default remote repository you would want to push and pull from. Subsequent calls to `git push` will not require `-u`.
{% endhint %}

Once done, you can navigate back to the Github repository and refresh the page. You will notice the following:

<figure><img src="/files/0Tx23FGhjsI2nmPJAhgU" alt=""><figcaption></figcaption></figure>

If you open `hello.txt`, you'll also see that it has `Hello World` in it.

## Cloning remote repositories

What you have just accomplished is the "push" workflow where you push an existing local repository to Github. However, there may be times where you want to create a remote repository first and use it locally. This can be done via the "pull" workflow or "clone" workflow.

{% hint style="info" %}
The clone workflow is useful when you want to work off of your friend's repositories and they have already uploaded their local repository to Github.
{% endhint %}

We will be working off of the same Github repository. Suppose that you want to create a copy of the remote repository on your local machine. You can do so with the following.

Ensure that you navigate out of the current folder:

```
cd ../
```

Then, use the `git clone` command:

```
git clone git@github.com:<github username>/<repository name>.git another-folder/
```

{% hint style="info" %}
The `another-folder/` at the end is crucial as it tells Git to create a copy of the remote repository but store it under a different folder name (other than `<repository name>`)
{% endhint %}

Then, you can navigate into the folder and view `hello.txt`:

```
cd another-folder/
cat hello.txt
```

Regardless of the method you have used, you have now integrated a local repository with a remote one! Let's move on to the final two fundamental concepts: branching and merge conflicts.


---

# Agent Instructions: 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://wiki.nushackers.org/orbital/git/fundamental-concepts/integrating-remote-repositories.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.
