JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Git >

Creating a remote repository from a local repository in Git

Author:JIYIK Last Updated:2025/03/30 Views:

This article discusses the necessary steps to create a remote repository based on a local repository. This is ideal when you have a local repository that needs to be available on a remote or SSH-enabled server.

Creating a remote repository from a local repository in Git

We will use a practical example to understand how to create a remote repository from a local repository.

example:

We will start by creating a simple repo on GitHub. We will call this repo Secondaryrepo.

Follow these steps:

  1. Log in to your GitHub account, click Repositories, and then click New to create a remote repository.
  2. Once created, go to the code and copy the URL of the repository.

On our computer, we have a delftscopetech repository with a remote tracking repository. To create a remote repository from this repository, we need to start a bare repository in our delftscopetech repository as shown below.

$ git init --bare

We can now add our remote (Secondaryrepo) repository to our empty repository. Recall that we already have remote tracking in the Delftscopetech repository.

To differentiate between the two remotes, we will use orign for this remote repository.

$ git remote add orign https://github.com/Wachira11ke/Secondaryrepo.git

Let's check if the remote repository exists.

$ git remote -v

git add remote origin

Now we can push to the remote Secondaryrepo repository as shown below.

$ git push -u orign

Note that you will push individual branches to the remote.

Output:

git push -u origin

Let's take a look at our remote repository on GitHub.

remote repository on GitHub

As we can see from the above two images, Git created a Dev2.1 branch in the remote repository and pushed all the commits to our local repository. Now, our local repository can push and pull from this remote.

In summary, we can create a remote repository based on a local repository. If your local repository has a tracking remote repository, it is best to start a bare repository before adding another remote repository.

It is recommended to give your remote a new name instead of origin. It makes it easy to distinguish between multiple remotes in one repo.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Changing drives in Git Bash

Publish Date:2025/03/30 Views:56 Category:Git

This short article will discuss how we can use Git Bash to have a Unix-style command line environment in Windows operating system and run multiple commands in this terminal. Git Bash Git is a collection of command-line utilities created to

Adding a remote branch in Git

Publish Date:2025/03/30 Views:142 Category:Git

Git does not allow its developers to create new branches on remote repositories. But instead, we can push an already existing local branch, and after doing so, we can bring it to the remote repository using some Git commands. In every versi

Synchronize your local repository with a remote repository in Git

Publish Date:2025/03/30 Views:92 Category:Git

This article outlines the process of syncing your local repository with a remote repository. We will also see how to sync a GitHub branch with a remote repository on the command line. Synchronize your local repository with a remote reposito

Creating and using branches in Git

Publish Date:2025/03/30 Views:99 Category:Git

This article introduces Git branches. We will see how Git branches can help you organize your projects. Some of the commands we will deal with are git branch and git checkout . git branch Use commands to create, display, and delete branches

Git force pull

Publish Date:2025/03/29 Views:166 Category:Git

In this tutorial, we will learn how to force pull changes from a remote repository in Git. Sometimes, we may need to discard local modifications and replace them with updates from a remote repository in a collaborative development environme

Git pulls Master into the branch

Publish Date:2025/03/29 Views:193 Category:Git

When developing software using the Git tool, you can create different branches for different features. When you make changes to master, these changes are not automatically added to other branches. This article will explain how to pull all t

Installing Git in Cygwin

Publish Date:2025/03/29 Views:116 Category:Git

Git is considered an active, innovative and highly recommended distributed version control system with a fantastic standalone command line while providing us with advanced features and complete internal methods. What is Cygwin Cygwin is con

Displaying remote repository information in Git

Publish Date:2025/03/29 Views:140 Category:Git

This tutorial is about displaying information about remote repositories in Git. We use Git, a version control system, to track changes made to files in our project directories through Git repositories. Usually, local repositories are tracke

Deleting a remote repository in Git

Publish Date:2025/03/29 Views:131 Category:Git

When we commit the wrong data to the origin, push it to the origin and merge it to the current branch. But later we realize that we don't need to do the merge in that repo, so the question here is how to undo or revert the merge commit that

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial