git将代码同时推送到github、oschina

发布时间:1970-01-01  编辑:Mrs.默先森 

    首先

    你需要有github码云账号

    这个自行搞定即可


    在github创建一个项目


    将项目导入到码云中


    将github项目clone到本地

    $ git clone https://github.com/Imasuperman/thinkphp5-crblog.git

    $ git clone https://github.com/Imasuperman/thinkphp5-crblog.git

    Cloning into 'thinkphp5-crblog'...

    remote: Counting objects: 3, done.

    remote: Compressing objects: 100% (2/2), done.

    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0

    Unpacking objects: 100% (3/3), done.


    进入项目目录

    $ cd thinkphp5-crblog/

    查看当前配置有哪些远程仓库

    $ git remote -v

    $ git remote -v

    originhttps://github.com/Imasuperman/thinkphp5-crblog.git (fetch)

    originhttps://github.com/Imasuperman/thinkphp5-crblog.git (push)

    可以看到目前只有github

     

    执行命令(origin-osc可改,它只是https://gitee.com/shuaibin/thinkphp5-crblog.git的别名):

    $ git remote add origin-osc https://gitee.com/shuaibin/thinkphp5-crblog.git

    再查看当前配置有哪些远程仓库

    $ git remote -v

    $ git remote -v

    originhttps://github.com/Imasuperman/thinkphp5-crblog.git (fetch)

    originhttps://github.com/Imasuperman/thinkphp5-crblog.git (push)

    origin-oschttps://gitee.com/shuaibin/thinkphp5-crblog.git (fetch)

    origin-oschttps://gitee.com/shuaibin/thinkphp5-crblog.git (push)

     

    将代码提交到github和码云

    在项目中创建测试文件

    依次执行命令即可提交至两个仓库

    $ git add -A
    $ git commit -m '描述'
    $ git push origin master
    $ git push origin-osc master

    $ git add -A

    $ git commit -m 'wubin.pro'

        [master 6821831] wubin.pro

         1 file changed, 0 insertions(+), 0 deletions(-)

         create mode 100644 index.php

    $ git push origin master

        Counting objects: 3, done.

        Delta compression using up to 8 threads.

        Compressing objects: 100% (2/2), done.

        Writing objects: 100% (3/3), 280 bytes | 280.00 KiB/s, done.

        Total 3 (delta 0), reused 0 (delta 0)

        To https://github.com/Imasuperman/thinkphp5-crblog.git

           6898f23..6821831  master -> master

    $ git push origin-osc master

        Counting objects: 3, done.

        Delta compression using up to 8 threads.

        Compressing objects: 100% (2/2), done.

        Writing objects: 100% (3/3), 280 bytes | 280.00 KiB/s, done.

        Total 3 (delta 0), reused 0 (delta 0)

        To https://gitee.com/shuaibin/thinkphp5-crblog.git

           6898f23..6821831  master -> master


    脚本简化操作

    vi push.sh

    在脚本中输入内容:

    #!/bin/bash
    git push origin master
    git push origin-osc master

    更改权限,给当前用户增加执行权限

    chmod u+x push.sh

    再进行提交时候,即可同时提交至两个托管仓库

    ./push.sh

    $ git add -A

    $ git commit -m '测试提交'

        [master 809004a] 测试提交

         2 files changed, 3 insertions(+)

         create mode 100644 b.txt

         create mode 100755 push.sh

    $ ./push.sh 

        Counting objects: 3, done.

        Delta compression using up to 8 threads.

        Compressing objects: 100% (3/3), done.

        Writing objects: 100% (3/3), 380 bytes | 380.00 KiB/s, done.

        Total 3 (delta 0), reused 0 (delta 0)

        To https://github.com/Imasuperman/thinkphp5-crblog.git

           6821831..809004a  master -> master

        Counting objects: 3, done.

        Delta compression using up to 8 threads.

        Compressing objects: 100% (3/3), done.

        Writing objects: 100% (3/3), 380 bytes | 380.00 KiB/s, done.

        Total 3 (delta 0), reused 0 (delta 0)

        To https://gitee.com/shuaibin/thinkphp5-crblog.git

           6821831..809004a  master -> master

    标签php nginx Linux


本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处,尊重他人劳动。

陶太富博客 http://blog.taotaifu.cn

最新发布

最新评论

0.066209s