简体   繁体   中英

How to git push to two repositories while git pull from one repository

I'm working on linux server (non-desktop) and I have two repositories. One is for development (github), the other is a local repository of my lab (gitlab).

What I need is to keep the two repositories always exactly the same, and I can push and pull on my dev repository, whereas only push on my local repository so that my colleagues can git pull from my lab repository. My lab-repository is used only for sharing my project with my colleagues: I do nothing but git push and they do nothing but git pull . That's all.

Well, you may ask why don't use the dev repository. That's because they have no right to connect to the Internet.

I don't like to execute many commands for each action. For example, for now I have to execute the commands below to git push to the two repositories:

cd devRepo
# coding here
# git add & git commit & git push here
cd ../myLabRepo
cp -r ../devRepo/* ./
# git add & git commit & git push here

This is kind of boring. Ofc, I know I can use bash script but I'm wondering if there are some specialized tool to do so or maybe Git has the capacity to do so.

You can add the whole stuff that you have into a bash script and run that. Otherwise, you can add a remote to your first repository and do a push there as well, instead of copying your whole project.

git add & git commit & git pull origin master & git push origin master & git push local master

You can specify more than one push location for the same remote.

git remote set-url --add --push <remote name> <push url> 

Check this with git remote -v

You should see the original push and fetch URLs, along with the extra push URL you just added.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM