10. Remote Storage
---------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
Environment: How to build a warehouse using your own Gitlab remote warehouse? Please click to build remote Warehouse Gitlab
Local Warehouse side: (under Windows git Bash)
To create an SSH key pair locally
$ Ssh-keygen-T Rsa-c"[email protected]"#创建ssh密钥对, all the way to enterGenerating Public/private RSA key pair. Enterfile inch whichTo save the key (/c/users/administrator/.SSH/Id_rsa):/c/users/administrator/.SSH/Id_rsa already exists. Overwrite (y/n)?yenter Passphrase (empty forno passphrase): Enter same passphrase Again:your identification has been savedinch/c/users/administrator/.SSH/Id_rsa. Your public key has been savedinch/c/users/administrator/.SSH/id_rsa.pub.The key fingerprint is:SHA256:X98ep2jnIQ0Rn/Spekqysliggfqwqo36xxlujh7g4ro [email protected]the key's Randomart image is:+---[RSA2048]----+| .. O. . || O *. O. || . * O. . . O | |. o =. o O ... | | o = so oo+. || o.o. ..... +.o | | Eo.. . .. =.+|| ..... o +o=+| | ... o. o+o o|+----[SHA256]-----+
To view the key pairs created:
$ cd~ #进入到用户主目录$ pwd #创建的密钥对的路径/c/users/Administrator$ ls-Altotal5699drwxr-xr-x1Administrator197121 0March - .: Wu./drwxr-xr-x1Administrator197121 0January - Ten: -.. /drwxr-xr-x1Administrator197121 0February4 at: About. Android/drwxr-xr-x1Administrator197121 0March at the: Geneva. eclipse/-rw-r--r--1Administrator197121 theMarch - .: Wu. GITCONFIGDRWXR-xr-x1Administrator197121 0March at the:Geneva. m2/drwxr-xr-x1Administrator197121 0February1 -: +. oracle_jre_usage/drwxr-xr-x1Administrator197121 0March - on: -. p2/Drwxr-xr-x 1 Administrator 197121 0 March 06:17. ssh/#创建的. SSH Key Pair Directory
$ cd. SSH # Enter the. SSH Key pair directory
$ ls #查看密钥对
Id_rsa id_rsa.pub known_hosts #将 A copy of the content in the id_rsa.pub for pasting into the remote warehouse SSH key pair.
To paste a key pair in the Remote warehouse web interface
To create a remote warehouse:
After the remote warehouse is established, there is a row of hints below the warehouse establishment:
This means that the local repository is uploaded to the remote repository operation.
-----------------------------------------------------------ready to start uploading the local repository to the remote repository-----------------------------------
$ git Remote add origin [email protected]:lhb/demo.git #在本地的git仓库登记远程仓库名origin和地址 [email protected]:lhb/demo.git$ git push-u Origin Master #将本地仓库的代码推送到 Remote repository ( note!) Attention! Attention! first push to add-u) the authenticity of host'Ubuntu (192.168.123.128)'Aa't be established.ECDSA Key fingerprint is sha256:+Td4iwxk0c4r9jtzli4u6az0fq74efzgnvetzkzytl8.are you sure your want to continue connecting (yes/no)?Yes #因为使用的是ssh协议, the first time to verify the fingerprint of the Gitlab server warning:permanently added'ubuntu,192.168.123.128'(ECDSA) to the list of known hosts. #提示: The Gitlab server has been added to a trusted any list counting objects: +, Done. Delta compression using up to4threads.compressing objects: -% ( -/ -), Done. Writing objects: -% ( +/ +),1.47KiB |0BYTES/S, Done. Total +(Delta4), reused0(Delta0) to [email PROTECTED]:LHB/Demo.git* [New branch] Master,Masterbranch Master set up to track remote branch master from Origin.
----------as long as the remote repository is registered locally-----------
Push it later.
Git push Origin Master
Why push local warehouse to remote warehouse to add a parameter-U after the push will not add it?
###########################################################################################git push-u origin Master [Origin indicates that the remote repository master represents the master branch of the local repository] Originally intended to be: git push master pushes the Mater branch of the local repository, but where does the push go without saying git push origin Master pushes the Mater branch of the local repository to the Origin branch of Git push-u Origin master pushes the Mater branch of the local repository to the Origin branch and registers the remote repository in the local repository origin- u = Up-stream will definitely ask where to register? In the local repository there is a config file [remote "origin"] url = [email protected]:lhb/demo.git fetch = +refs/heads/*: Refs/remotes/origin/*[branch "Master"] Remote = origin merge = Refs/heads/master#################### ##########################################################################
To clone project from the remote repository to Local:
To clone a warehouse, you must first know the address of the warehouse and then use the git clone
command clone.
GIT supports a variety of protocols, including https
, but with the fastest ssh
supported native git
protocols.
git clone [email protected]:lhb/demo.git
-----------------------------------a problem when pushing a local repository to a remote repository-------------------------------------
git problem, error:src Refspec master does not match any
$ git push-'[email protected]:lhb/quick4j.git'
Theory you need to know: The local repository is empty and an empty directory cannot be submitted (init only, no add and commit)
Solution:
$ git add-f *#将所有的文件都提交到暂存区 $ git commit-M"Add quick4j Project"#将暂存区的文档提交到. Git local repository
$ git push-u origin2 master #提交代码到远程仓库, before giving the remote repository the name is Origin2
Counting objects:4262, done.
Delta compression using up to 4 threads.
Compressing objects:100% (4017/4017), done.
Writing objects:100% (4262/4262), 80.23 MiB | 6.67 mib/s, done.
Total 4262 (Delta 1394), reused 0 (Delta 0)
to [email protected]:lhb/quick4j.git
* [New branch] Master, master
Branch Master set up to track remote Branch master from Origin2.
git usage (vi)