# Connecting a repository to a package

You can connect a repository to a package on GitHub.

When you publish a package that is scoped to a personal account or an organization, the package is not linked to a repository by default. If you connect a package to a repository, the package's landing page will show information and links from the repository, such as the README. You can also choose to have the package inherit its access permissions from the linked repository. For more information, see [Configuring a package's access control and visibility](/en/enterprise-server@3.22/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility).

## Connecting a repository to a user-scoped package on GitHub

1. On GitHub, navigate to the main page of your personal account.

2. In the top right corner of GitHub, click your profile picture, then click **Your profile**.

   ![Screenshot of the dropdown menu under @octocat's profile picture. "Your profile" is outlined in dark orange.](/assets/images/help/profile/profile-button-avatar-menu-global-nav-update.png)

3. On your profile page, in the header, click the **<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-package" aria-label="package" role="img"><path d="m8.878.392 5.25 3.045c.54.314.872.89.872 1.514v6.098a1.75 1.75 0 0 1-.872 1.514l-5.25 3.045a1.75 1.75 0 0 1-1.756 0l-5.25-3.045A1.75 1.75 0 0 1 1 11.049V4.951c0-.624.332-1.201.872-1.514L7.122.392a1.75 1.75 0 0 1 1.756 0ZM7.875 1.69l-4.63 2.685L8 7.133l4.755-2.758-4.63-2.685a.248.248 0 0 0-.25 0ZM2.5 5.677v5.372c0 .09.047.171.125.216l4.625 2.683V8.432Zm6.25 8.271 4.625-2.683a.25.25 0 0 0 .125-.216V5.677L8.75 8.432Z"></path></svg> Packages** tab.

4. Search for and then click the name of the package that you want to manage.

5. Under your package versions, click **Connect repository**.

6. Select a repository to link to the package, then click **Connect repository**.

## Connecting a repository to an organization-scoped package on GitHub

1. On GitHub, navigate to the main page of your organization.
2. Under your organization name, click the **<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-package" aria-label="package" role="img"><path d="m8.878.392 5.25 3.045c.54.314.872.89.872 1.514v6.098a1.75 1.75 0 0 1-.872 1.514l-5.25 3.045a1.75 1.75 0 0 1-1.756 0l-5.25-3.045A1.75 1.75 0 0 1 1 11.049V4.951c0-.624.332-1.201.872-1.514L7.122.392a1.75 1.75 0 0 1 1.756 0ZM7.875 1.69l-4.63 2.685L8 7.133l4.755-2.758-4.63-2.685a.248.248 0 0 0-.25 0ZM2.5 5.677v5.372c0 .09.047.171.125.216l4.625 2.683V8.432Zm6.25 8.271 4.625-2.683a.25.25 0 0 0 .125-.216V5.677L8.75 8.432Z"></path></svg> Packages** tab.

   ![Screenshot of @octo-org's profile page. The "Packages" tab is highlighted with an orange outline.](/assets/images/help/package-registry/org-tab-for-packages-with-overview-tab.png)
3. Search for and then click the name of the package that you want to manage.
4. Under your package versions, click **Connect repository**.
5. Select a repository to link to the package, then click **Connect repository**.

## Connecting a repository to a container image using the command line

> \[!NOTE] Container registry is currently in public preview for GitHub Enterprise Server and subject to change.

Both GitHub Packages and subdomain isolation must be enabled to use Container registry. For more information, see [Working with the Container registry](/en/enterprise-server@3.22/packages/working-with-a-github-packages-registry/working-with-the-container-registry).

1. In your Dockerfile, add this line, replacing `HOSTNAME`, `OWNER` and `REPO` with your details:

   ```shell
   LABEL org.opencontainers.image.source=https://HOSTNAME/OWNER/REPO
   ```

   For example, if you're the user `octocat` and own `my-repo`, and your GitHub hostname is `github.companyname.com`, you would add this line to your Dockerfile:

   ```shell
   LABEL org.opencontainers.image.source=https://containers.github.companyname.com/octocat/my-repo
   ```

   For more information, see [LABEL](https://docs.docker.com/engine/reference/builder/#label) in the official Docker documentation and [Pre-defined Annotation Keys](https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys) in the `opencontainers/image-spec` repository.

2. Build your container image. This example builds an image from the Dockerfile in the current directory and assigns the image name `hello_docker`.

   ```shell
   docker build -t hello_docker .
   ```

3. Optionally, review the details of the Docker image you just created.

   ```shell
   $ docker images
   > REPOSITORY          TAG         IMAGE ID       CREATED         SIZE
   > hello_docker        latest      142e665b1faa   5 seconds ago   125MB
   > redis               latest      afb5e116cac0   3 months ago    111MB
   > alpine              latest      a6215f271958   5 months ago    5.29MB
   ```

4. Assign a name and hosting destination to your Docker image.

   ```shell
   docker tag IMAGE_NAME containers.HOSTNAME/NAMESPACE/NEW_IMAGE_NAME:TAG
   ```

   Replace `NAMESPACE` with the name of the personal account or organization to which you want the package to be scoped.

   For example:

   ```shell
   docker tag 38f737a91f39 containers.github.companyname.com/octocat/hello_docker:latest
   ```

5. If you haven't already, authenticate to the Container registry. For more information, see [Working with the Container registry](/en/enterprise-server@3.22/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry).

   ```shell
   $ echo $CR_PAT | docker login containers.HOSTNAME -u USERNAME --password-stdin
   > Login Succeeded
   ```

6. Push your container image to the Container registry.

   ```shell
   docker push containers.HOSTNAME/NAMESPACE/IMAGE-NAME:TAG
   ```

   For example:

   ```shell
   docker push containers.github.companyname.com/octocat/hello_docker:latest
   ```

## Unlinking a repository from a package on GitHub

> \[!NOTE]
> Unlinking a package from a repository will remove the repository information from the package's landing page and can affect the access pattern depending on whether the package inherits its access permissions from the repository. For more information, see [Configuring a package's access control and visibility](/en/enterprise-server@3.22/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility#about-inheritance-of-access-permissions). This behavior does not apply to Apache Maven packages, as outlined in [About permissions for GitHub Packages](/en/enterprise-server@3.22/packages/learn-github-packages/about-permissions-for-github-packages#granular-permissions-for-userorganization-scoped-packages).

1. On GitHub, navigate to the settings page of the Package you'd like to unlink.

2. On the Package settings page, you will see a Repository source section. If this section is not present, then the Package is not currently linked to a repository.

3. Click on the trash icon in the top right corner of the Repository source section.

> It is possible that the Repository source section exists, but there is no trash icon present. This is because a repository source has been defined as part of the packaged code i.e. a `package.json` file, `.gemspec` file, however, it is not actually linked to a repository on GitHub. To link the package to a repository, you will need to follow the steps in the section above.

1. Confirm that you would like to unlink the repository from the package with the dialogue.

## Migrating a package to another repository

If you currently have a package linked to a repository and you would like to link it to a different repository, this can be done by unlinking the package from the current repository and linking it to the new repository.

1. Follow the steps to unlink it, see [Unlinking a repository from a package on GitHub](/en/enterprise-server@3.22/packages/learn-github-packages/connecting-a-repository-to-a-package#unlinking-a-repository-from-a-package-on-github).
2. Follow the steps to link the package to the new repository, see [Connecting a repository to an organization-scoped package on GitHub](/en/enterprise-server@3.22/packages/learn-github-packages/connecting-a-repository-to-a-package#connecting-a-repository-to-an-organization-scoped-package-on-github) or [Connecting a repository to a user-scoped package on GitHub](/en/enterprise-server@3.22/packages/learn-github-packages/connecting-a-repository-to-a-package#connecting-a-repository-to-a-user-scoped-package-on-github).