Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to track multiple Git remote repositories in linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to track multiple Git remote repositories in linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Having consistent naming standards is the key to keeping local and upstream Git repositories consistent.

When the naming of the local Git repository is not consistent with that of the remote repository, collaboration with the remote repository becomes confusing.

One way to solve this problem is to standardize the use and meaning of the two words: origin refers to your personal example.com//* repository, while upstream refers to the example.com repository that you copy fork from the origin warehouse. In other words, upstream refers to the upstream repository that publicly submits work, while origin refers to your local copy of the upstream repository, for example, you generate a pull request pull request (PR) from here.

Taking the pbench repository as an example, the following is a step-by-step way to build a new local clone, where the definitions of origin and upstream are the same.

1. On most Git hosting services, you have to copy it when you want to work on it. This is not necessary when you run your own Git server, but for an open code base, it is an easy way to transfer differences between contributors.

Create a replica of the Git repository. In this example, suppose your copy is located in example.com//pbench.

2. Next, you must obtain a uniform Resource Identifier (URI) in order to clone the cloning through SSH. On most Git hosting services, such as GitLab or GitHub, you can copy the clone URI to the clipboard on a button or panel labeled "Clone" or "Clone over SSH".

3. In your development system, use the URI clone repository you copied:

$git clone git@example.com:/pbench.git

This will clone the Git repository with the default name origin as your pbench repository replica.

4. Change to the directory you just cloned:

$cd ~ / pbench

5. Next, get the SSH URI of the source repository (the one you originally copied). This may be the same as the method above. Locate the "Clone" button or panel and copy the clone address. In software development, this is often referred to as "upstream" because (theoretically) this is where most commits take place, and you intend to allow them to flow to downstream repositories.

6. Add URI to your local warehouse. Yes, there will be two different remote warehouses assigned to your local warehouse copy:

$git remote add upstream git@example.com:bigproject/pbench.git

Now you have two named remote repositories: origin and upstream. You can view your remote warehouse with the remote subcommand:

$git remote-v

Right now, your local master branch is tracking origin's master, which is not necessarily what you want. You may want to track the upstream version of this branch, as most of the development is upstream. The idea is that you want to add changes to the content you get from upstream.

8. Change your local master branch to track upstream/master:

$git fetch upstream$ git branch-set-upstream-to=upstream/master master

You can do this for any branch you want, not just master. For example, some projects use dev branches to handle all unstable changes, leaving master for code that has been approved for release.

9. Once you have set up your tracking branch, be sure to rebase your master branch to keep it in line with any new changes in the upstream warehouse:

$git remote update$ git checkout master$ git rebase Thank you for your reading! This is the end of this article on "how to track multiple Git remote repositories in linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report