JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

Pushing from an existing remote repository to another remote repository in Git

Author:JIYIK Last Updated:2025/04/20 Views:

This tutorial will teach you how to push from an existing remote repository to a different remote repository in Git.

Git is a version control system used to track changes in a project directory. Git uses commits for such purposes.

In Git, you set up a local repository and its branches to track a remote repository and its branches.

Sometimes, we may want to push the changes done in our local repository to a different remote repository, instead of the existing one. We can use git remotethe push command for this purpose.

We will now illustrate this with an example.


Pushing from an existing remote repository to a different remote repository in Git

Git is used in collaborative development environments to track modifications made to files in a project directory. In Git, we usually set up a local repository and its branches to track a remote Git repository and its branches.

We use git pullthe command to pull changes from the Git remote repository to the local repository, and use git pushthe command to push changes to the remote.

Sometimes, we may want to push changes to a different remote repository than the existing one, the one we used to pull in the remote changes.

Assume that we https://git.fedorahosted.org/have a repository named hosted on server My_Project. We have to clone the Git repository on our local machine My_Project.

We can then pull and push changes to and from an existing remote repository hosted on server by executing the git pulland commands, respectively.git pushhttps://git.fedorahosted.org/

We now want to push our changes to a different remote Git repository hosted on a different server https://github.com/.

First, we need to My_Projectcreate a new remote Git repository on the server called Github.

We have cloned https://git.fedorahosted.org/the remote repository hosted on the server on our local machine My_Project. We will now originrename the remote given by the alias to upstream, as shown below.

$ git remote rename origin upstream

After this, we need to git remoteadd the new and different remote repository URL hosted on Github using the command as shown below.

$ git remote add origin https://github.com/johndoe/My_Project.git

So, now we have set up a different remote Git repository URL. We can now git pushpush our local changes to the remote repository hosted on Github using the command as shown below.

$ git push origin master

We can still use the command to pull changes from the original and existing remote repositories hosted on git pullthe server .https://git.fedorahosted.org/

$ git pull upstream master

So, we learned how to push from an existing remote repository to a different remote repository in Git.

For more information, visit the following sources:

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

Update the repository remotely by setting

Publish Date:2025/04/20 Views:120 Category:OPERATING SYSTEM

In this tutorial, we will discuss how to set up the central repository as a remote for our local repository so that our branch is updated whenever the central repository changes. We should always perform this step before making edits to our

Rename Git repository

Publish Date:2025/04/20 Views:100 Category:OPERATING SYSTEM

In this article, we will discuss renaming Git repositories. We can explain this in different ways. It can rename the displayed name, the repository on GitHub, or the folder of the repository. We will discuss these and go through the steps w

Creating tags in a Git repository

Publish Date:2025/04/20 Views:117 Category:OPERATING SYSTEM

In this tutorial, we will discuss how to create tags in a Git repository. Creating tags in a Git repository In Git, we may want to mark certain commits or specific points in the history of the project repository. To do this, we can use the

Push Git tags to remote repositories

Publish Date:2025/04/20 Views:177 Category:OPERATING SYSTEM

If you create a git tag locally, your intention must be to share your changes with your team for easy tracking. Commit is one of the common operations to share changes. But another sharing and tracking idea added to it is Git Tags. This art

Ignore untracked files in Git

Publish Date:2025/04/20 Views:162 Category:OPERATING SYSTEM

This article will discuss two methods that can be used to ignore untracked files in a Git repository. If there are multiple untracked files and folders in your local repository, running the git status command will output many lines. Let’s

Ignore everything except certain files in Git

Publish Date:2025/04/20 Views:151 Category:OPERATING SYSTEM

This article outlines the steps to make Git ignore all but a few files in a Git repository. The .gitignore file is a useful Git utility that allows us to tell Git which files to track and which files not to track. If you want your .gitignor

Get the current branch in Git

Publish Date:2025/04/20 Views:57 Category:OPERATING SYSTEM

This article describes how to use git branch the command and git symbolic-ref the command to get the branch you are currently working on in git. Get the current branch Use git branch the command to get a list of all branches. The branch nam

Update branches from master in Git

Publish Date:2025/04/20 Views:142 Category:OPERATING SYSTEM

When working in Git with many developers and analysts working on various branches simultaneously, we may encounter many problems. A common problem is when one team member makes changes in his local branch while others work on that remote br

Scan to Read All Tech Tutorials

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

Recommended

Tags

Scan the Code
Easier Access Tutorial