Build git project local image

Time:2019-12-16

Create a git user and user group on the server

sudo adduser git

Set the corresponding information according to the prompt

Set the permissions of GIT home directory to git, otherwise you will not be able to access it in the future

sudo chown -R git:git /home/git/

Use git clone — mirror to clone the project on GitHub to local:

#Create a gitmirror directory to be used as a transit directory for images
[email protected]:~$ mkdir gitmirror
[email protected]:~$ cd gitmirror/
#Add local SSH public key on githua
[email protected]:~/gitmirror$ cat ~/.ssh/
id_rsa       id_rsa.pub   known_hosts  
[email protected]:~/gitmirror$ cat ~/.ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDF5picVZ1nut052WI2RHGFxVVkTdcU3KYejxKBrclxwB/XG6KcLcES7lMkvJngWRPzCWElJVYrfHAAUkM/El6TwoJsO3/D8TK+FEfeVsTKaRC2+TYoYLiKdOCyH75LJ8zZYJYDJvC51WOBlEWWBD3C0mG33mFmCupXvUXlbrnGOJWRTnPWe98+oY/a2inxZkNrMfNN5leKzoOtx4tX+/26IccGAroALA+sDHCrDZZ89Yy5Jlmv4K4FuG5w9LXHQBCTUYPrQfBhnTwwLGQg8ImU4WixPjHeBK97XeE4SS8EYx6K7Z3UBBuSS3kEadminfi6R+m1Z0IeOoTe2ZrLadminUEAhL [email protected]
[email protected]:~/gitmirror$ 
#Clone the project locally with the -- mirror option
[email protected]:~/gitmirror$ git clone --mirror [email protected]:ouyangxb/study-rebase.git
Cloning into bare repository 'study-rebase.git'...
Warning: Permanently added the RSA host key for IP address '140.82.113.4' to the list of known hosts.
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 9 (delta 0), reused 6 (delta 0), pack-reused 0
Receiving objects: 100% (9/9), done.
Checking connectivity... done.
[email protected]:~/gitmirror$

Create the directory of GIT project we need to mirror and initialize it as a warehouse:

[email protected]:~/repos$ mkdir study-rebase.git
[email protected]:~/repos$ cd study-rebase.git/
[email protected]:~/repos/study-rebase.git$ git init --bare       
Initialized empty Git repository in /home/git/repos/study-rebase.git/
[email protected]:~/repos/study-rebase.git$ 

Set the local repo for the project

#Set project local repo address
[email protected]:~/gitmirror/study-rebase.git$ git remote set-url --push origin [email protected]:/home/git/repos/study-rebase.git
#Push project to local repo
[email protected]:~/gitmirror/study-rebase.git$ git push --mirror 
[email protected]'s password: 
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (9/9), 1.08 KiB | 0 bytes/s, done.
Total 9 (delta 0), reused 9 (delta 0)
To [email protected]:/home/git/repos/study-rebase.git
 * [new branch]      dev -> dev
 * [new branch]      master -> master
[email protected]:~/gitmirror/study-rebase.git$

test

[email protected]:~$ git clone [email protected]:/home/git/repos/study-rebase.git
Cloning into 'study-rebase'...
[email protected]'s password: 
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 9 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (9/9), done.
Checking connectivity... done.
[email protected]:~$ 

Synchronize changes of remote repo on GitHub to local repo

Modify repo information on GitHub

[email protected]:~$ git clone [email protected]:ouyangxb/study-rebase.git
Cloning into 'study-rebase'...
Warning: Permanently added the RSA host key for IP address '140.82.114.3' to the list of known hosts.
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 9 (delta 0), reused 6 (delta 0), pack-reused 0
Receiving objects: 100% (9/9), done.
Checking connectivity... done.
[email protected]:~$ 
[email protected]:~$ 
[email protected]:~$ cd study-rebase
[email protected]:~/study-rebase$ 
[email protected]:~/study-rebase$ ls
README.md
[email protected]:~/study-rebase$ 
#Modify the readme.md file and submit a modification record to the remote GitHub
[email protected]:~/study-rebase$ vim README.md 
# study-rebase
study rebase
git server

~
[email protected]:~/study-rebase$ 
[email protected]:~/study-rebase$ git add .
[email protected]:~/study-rebase$ git commit -m "study git mirror"                
[master c5c3bac] study git mirror
 1 file changed, 2 insertions(+)
[email protected]:~/study-rebase$ 
[email protected]:~/study-rebase$ 
[email protected]:~/study-rebase$ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1/1), done.
Writing objects: 100% (3/3), 274 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:ouyangxb/study-rebase.git
   811986a..c5c3bac  master -> master
[email protected]:~/study-rebase$ 
[email protected]:~/study-rebase$ git log
commit c5c3bac6758440d64b9151d1e138d8131d023aaf
Author: Your Name <[email protected]>
Date:   Sun Dec 8 02:24:05 2019 -0500

    study git mirror

commit 811986a7a427e51e8519505525000904a626802c
Author: ouyangxb <[email protected]>
Date:   Wed Nov 27 18:08:00 2019 +0800

    Initial commit
[email protected]:~/study-rebase$

Synchronize to the local repo staging directory and then to the local repo

[email protected]:~/gitmirror/study-rebase.git$ 
[email protected]:~/gitmirror/study-rebase.git$ git fetch -p origin 
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:ouyangxb/study-rebase
   811986a..c5c3bac  master     -> master
[email protected]:~/gitmirror/study-rebase.git$ git push --mirror 
[email protected]'s password: 
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1/1), done.
Writing objects: 100% (3/3), 274 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/home/git/repos/study-rebase.git
   811986a..c5c3bac  master -> master
[email protected]:~/gitmirror/study-rebase.git$ 

Check whether the local repo has updates

[email protected]:~/gitmirror/study-rebase.git$ git log
commit c5c3bac6758440d64b9151d1e138d8131d023aaf
Author: Your Name <[email protected]>
Date:   Sun Dec 8 02:24:05 2019 -0500

    study git mirror

commit 811986a7a427e51e8519505525000904a626802c
Author: ouyangxb <[email protected]>
Date:   Wed Nov 27 18:08:00 2019 +0800

    Initial commit
[email protected]:~/gitmirror/study-rebase.git$ 

Local workspace update

[email protected]:~/study-rebase$ git remote -v
origin  [email protected]:/home/git/repos/study-rebase.git (fetch)
origin  [email protected]:/home/git/repos/study-rebase.git (push)
[email protected]:~/study-rebase$ git pull
[email protected]'s password: 
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From 172.17.0.1:/home/git/repos/study-rebase
   811986a..c5c3bac  master     -> origin/master
Updating 811986a..c5c3bac
Fast-forward
 README.md | 2 ++
 1 file changed, 2 insertions(+)
[email protected]:~/study-rebase$ git log
commit c5c3bac6758440d64b9151d1e138d8131d023aaf
Author: Your Name <[email protected]>
Date:   Sun Dec 8 02:24:05 2019 -0500

    study git mirror

commit 811986a7a427e51e8519505525000904a626802c
Author: ouyangxb <[email protected]>
Date:   Wed Nov 27 18:08:00 2019 +0800

    Initial commit
[email protected]:~/study-rebase$ 

Recommended Today

Sharing 10 useful methods of laravel 5.8 sets

This article is forwarded from the professional laravel developer community, original link: https://learnku.com/laravel/t… In laravel, there is a very useful class for manipulating arrays, called collections. I believe that every developer of laravel has used the collection more or less, especially when operating eloquent. In this article, I will list 10 common methods. 1. Weight […]