在服务器上创建git用户和用户组sudoaddusergit将git主目录的权限设置为git根据提示设置相应信息,否则将无法访问sudochown-Rgit:git/home/git/使用gitclone--mirror将github上的项目克隆到本地:#创建一个gitmirror目录,用于镜像传输目录git@localhost:~$mkdirgitmirrorgit@localhost:~$cdgitmirror/#添加本地ssh公钥git@localhostongithua:~/gitmirror$cat~/.ssh/id_rsaid_rsa.pubknown_hostsgit@localhost:~/gitmirror$cat~/.ssh/id_rsa.pubssh-rsaAAAAB3NzaC1yc2EAAAADAQABAAABAQDF5picVZ1nut052WI2RHGFxVVkTdcU3KYejxKBrclxwB/XG6KcLcES7lMkvJngWRPzCWElJVYrfHAAUkM/El6TwoJsO3/D8TK+FEfeVsTKaRC2+TYoYLiKdOCyH75LJ8zZYJYDJvC51WOBlEWWBD3C0mG33mFmCupXvUXlbrnGOJWRTnPWe98+oY/a2inxZkNrMfNN5leKzoOtx4tX+/26IccGAroALA+sDHCrDZZ89Yy5Jlmv4K4FuG5w9LXHQBCTUYPrQfBhnTwwLGQg8ImU4WixPjHeBK97XeE4SS8EYx6K7Z3UBBuSS3kEadminfi6R+m1Z0IeOoTe2ZrLadminUEAhLgit@localhostgit@localhost:~/gitmirror$#携带--mirror选项将项目克隆到本地git@localhost:~/gitmirror$gitclone--mirrorgit@github.com:ouyangxb/study-rebase.git克隆到裸存储库'study-rebase.git'..警告:将IP地址“140.82.113.4”的RSA主机密钥永久添加到已知主机列表中。远程:枚举对象:9,完成。远程:计数对象:100%(9/9),完成。远程:压缩对象:100%(4/4),完成。远程:总计9(delta0),重复使用6(delta0),打包重复使用0接收对象:100%(9/9),完成。正在检查连接...done.git@localhost:~/gitmirror$创建我们需要镜像的git项目目录,并初始化为仓库:git@localhost:~/repos$mkdirstudy-rebase.gitgit@localhost:~/repos$cdstudy-rebase.git/git@localhost:~/repos/study-rebase.git$gitinit--bare在/home/git/repos/study-rebase.git/git@localhost:~/repos中初始化空Git存储库/study-rebase.git$设置项目本地Repo#设置项目本地Repo地址git@localhost:~/gitmirror/study-rebase.git$gitremoteset-url--pushorigingit@172.17.0.1:/home/git/repos/study-rebase.git#将项目推送到本地repogit@localhost:~/gitmirror/study-rebase.git$gitpush--mirrorgit@172.17.0.1的密码:Counting对象:9,done.Deltacompression使用最多4个线程。压缩对象:100%(4/4),完成。写入对象:100%(9/9),1.08KiB|0字节/秒,完成。总计9(delta0),重复使用9(delta0)至git@172.17.0.1:/home/git/repos/study-rebase.git*[newbranch]dev->dev*[新分支]master->mastergit@localhost:~/gitmirror/study-rebase.git$测试admin@localhost:~$gitclonegit@172.17.0.1:/home/git/repos/study-rebase.gitCloninginto'study-rebase'...git@172.17.0.1的密码:remote:Countingobjects:9,done.remote:Compressingobjects:100%(4/4),done.remote:Total9(delta0),reused0(delta0)Receivingobjects:100%(9/9),done.Checkingconnectivity...done.admin@localhost:~$同步github上的远程repo的变化到本地repo修改github上的repo信息git@localhost:~$gitclonegit@github.com:ouyangxb/study-rebase.gitCloninginto'study-rebase'...警告:将IP地址“140.82.114.3”的RSA主机密钥永久添加到已知主机列表中。远程:枚举对象:9,done.remote:Countingobjects:100%(9/9),done.remote:Compressingobjects:100%(4/4),done.remote:Total9(delta0),reused6(delta0),pack-reused0接收对象:100%(9/9),完成。检查连接...完成。git@localhost:~$git@localhost:~$git@localhost:~$cdstudy-rebasegit@localhost:~/study-rebase$git@localhost:~/study-rebase$lsREADME.mdgit@localhost:~/study-rebase$#修改README.md文件,提供一个修改记录到远程github上git@localhost:~/study-rebase$vimREADME.md#study-rebasestudyrebasegit服务器~git@localhost:~/study-rebase$git@localhost:~/study-rebase$gitadd.git@localhost:~/study-rebase$gitcommit-m"studygitmirror"[masterc5c3bac]studygitmirror1filechanged,2insertions(+)git@localhost:~/study-rebase$git@localhost:~/study-rebase$git@localhost:~/study-rebase$gitpushCounting对象:3,完成。最多使用4个线程进行增量压缩。压缩对象:100%(1/1),完成。写入对象:100%(3/3),274字节|0字节/秒,完成。总计3(delta0),reused0(delta0)到git@github.com:ouyangxb/study-rebase.git811986a..c5c3bacmaster->mastergit@localhost:~/study-rebase$git@localhost:~/study-rebase$gitlogcommitc5c3bac6758440d64b9151d1e138d8131d023aafAuthor:YourName
