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

Git multiple remote warehouses

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

1. preface

   I have been using GitHub to manage my own open source projects for a few years. In the last year, I have updated more and more, and the repositories are getting bigger and bigger. Sometimes I feel that GitHub is too slow, especially recently, I feel more obvious, so I have the idea of finding a domestic code hosting platform similar to GitHub. At the same time, I also want to continuously update the repository on GitHub, so I need a local repository (my own development machine) and multiple remote repositories (Github, code cloud, coding).

2. git config for a remote repository

   My open source project Nebula, an event-driven high-performance TCP networking framework, has a git configuration file.git/config as follows:

[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true[remote "origin"] url = https://github.com/Bwar/Nebula.git fetch = +refs/heads/*:refs/remotes/origin/*[branch "master"] remote = origin merge = refs/heads/master3. Add multiple remote repositories using the git command line

   Add a remote repository named " mirror ":

git remote add mirror https://gitee.com/Bwar/Nebula.git

   After executing this command, the contents of the.git/config file become:

[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true[remote "origin"] url = https://github.com/Bwar/Nebula.git fetch = +refs/heads/*:refs/remotes/origin/*[branch "master"] remote = origin merge = refs/heads/master[remote "mirror"] url = https://gitee.com/Bwar/Nebula.git fetch = +refs/heads/*:refs/remotes/mirror/*

   At this point, there was already one local warehouse and two remote warehouses. Use the following commands to pull and push from and to two remote repositories, respectively.

git pull origin master git pull mirror mastergit push origin master git push mirror master4. Update multiple remote repositories simultaneously with one command

  At present, my open source project only has one contributor (plans to introduce other contributors in December 2018), the main push is less pull, I find it troublesome to enter multiple commands, and one command updates the current branch to two remote repositories at the same time to make me satisfied. So change it, do not use the mirror method above, directly add a url to origin to implement a local repository and multiple remote repositories.

git remote set-url --add origin https://gitee.com/Bwar/Nebula.git

  After executing this command, the.git/config content becomes:

[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true[remote "origin"] url = https://github.com/Bwar/Nebula.git url = https://gitee.com/Bwar/Nebula.git fetch = +refs/heads/*:refs/remotes/origin/*[branch "master"] remote = origin merge = refs/heads/master[remote "mirror"] url = https://gitee.com/Bwar/Nebula.git fetch = +refs/heads/*:refs/remotes/mirror/*

  It doesn't matter whether the " mirror " added before is kept or deleted. At this time, we can update two remote repositories with one command:

git push origin master5. Password-free remote warehouse operation

  To execute remote warehouse operation, it is a troublesome thing to input password. You can avoid such trouble by matching user name and password in url of configuration file and improve operation efficiency. Password-free remote warehouse operation can also be achieved through ssh mode, the following only gives https mode password configuration:

url = https://${user}:${password}@github.com/Bwar/Nebula.git

  Just substitute " ${user} " and " ${password} " in the configuration above with your remote repository username and password.

6. Directly modify git configuration file to achieve multiple remote repositories

  The above command git remote to complete a local repository multiple remote repository configuration, these commands are actually achieved by modifying.git/config, in fact, directly modify the configuration file may be faster, I am directly modify the configuration file to complete. Finally, my multiple remote repositories are configured as follows:

[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true[remote "origin"] url = https://${user}:${password}@github.com/Bwar/Nebula.git url = https://${user}:${password}@gitee.com/Bwar/Nebula.git url = https://${user}:${password}@git.coding.net/Bwar/NebulaBootstrap.git fetch = +refs/heads/*:refs/remotes/origin/*[branch "master"] remote = origin merge = refs/heads/master

  Over.

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

Internet Technology

Wechat

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

12
Report