Git 推送本地所有分支和拉取远程所有分支

时间:2018-12-26
本文章向大家介绍Git 推送本地所有分支和拉取远程所有分支,主要包括Git 推送本地所有分支和拉取远程所有分支使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

本文是另外一篇博文 Win10 Ubuntu子系统设置Git服务器和SSH Server 证书登录,实现win10和macOS源码同步 的一部分,单独拿出来说一下:

首先设置好远程Git Server的ssh证书登录,假设用户名是git,远程服务器Host设置为nas (具体设置参考上述博文)

1. 推送本地所有分支

首先在远程服务器上初始化一个bare仓库,

$ sudo git init --bare smartlight.git

输入密码就可以看到初始化信息?

[sudo] password for git:
Initialized empty Git repository in /mnt/f/gitRepo/smartlight.git/

本地仓库添加remote路径

git remote add origin ssh://git@nas/mnt/f/gitRepo/smartlight.git

然后使用git push --all origin 推送

$ git push --all origin

即可以看到类似下面的信息

Counting objects: 232, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (214/214), done.
Writing objects: 100% (232/232), 8.08 MiB | 2.08 MiB/s, done.
Total 232 (delta 37), reused 0 (delta 0)
remote: Resolving deltas: 100% (37/37), done.
To ssh://nas/mnt/f/gitRepo/Smartlight.git
 * [new branch]      master -> master

 2. 拉取远程所有分支

注意,简单使用git clone ,git fetch --all, git pull --all 都不能全部一次获取远程的所有分支,他们都只对master分支起作用,所以一次性拉取所有远程分支到本地应该使用 git clone的--mirror参数,但是这样会把它初始化为一个bare仓库,所以需要去掉这个属性 , 依次输入以下三个命令即可:
 

>git clone --mirror ssh://git@nas/mnt/f/gitRepo/smartlight.git
>cd smartlight.git
>git config --bool core.bare false