How to use gitee website

本地Git仓库:
1. 设置。自报家门
git config --global user.name "happygrilclh"
git config --global user.email "[email protected]"

2. 在本地,创建一个空目录
mkdir git_repository
cd git_repository

3. 通过git init命令把这个目录变成Git可以管理的仓库
$ git init
Initialized empty Git repository in D:/git_repository/.git/

4. 在git_repository下,新建一个文件test0415.txt
Git is a version control system.
Git is free software.

5.命令git add告诉Git,把文件添加到仓库
  git add test0415.txt
6. 用命令git commit告诉Git,把文件提交到仓库:
git commit -m "wrote a readme file"
[master (root-commit) a4c39c2] wrote a readme file
 1 file changed, 2 insertions(+)
 create mode 100644 test0415.txt
 
 
远程仓库
1. 你的本地Git仓库和GitHub仓库之间的传输是通过SSH加密的。
第1步:创建SSH Key。在用户主目录下,看看有没有.ssh目录。
如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接跳到下一步。
如果没有,打开Shell(Windows下打开Git Bash),创建SSH Key:
ssh-keygen -t rsa -C "[email protected]"

$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
/c/Users/Administrator/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:6xmJbqCr8Nxscy4eyQOr+9i3sp1cXv+vWPohCfrJ3P8 [email protected]
The key's randomart image is:
+---[RSA 3072]----+
|                 |
|                 |
|                 |
|                 |
|  .     S        |
|   +.. o + .     |
|. ..=.+ = o o    |
|.*o==Bo* * = .   |
|=+BBOB+ B =+=+E  |
+----[SHA256]-----+

然后一路回车,使用默认值即可,由于这个Key也不是用于军事目的,所以也无需设置密码。
用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,
这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。
2. gitee 网站,设置,添加SSH公钥。
3. 在gitee网站,新建一个仓库
4. 克隆代码到本地
git clone https://gitee.com/happygrilclh/project.git

5. 从远程获取最新版本到本地
git pull origin master

更新本地代码到远程仓库的方法:
方法1、先将仓库clone到本地,修改后再push到码云的仓库仓库
$ git clone https://gitee.com/happygrilclh/project.git 		#将远程仓库克隆到本地
在本地仓库,新建一个文件test0415。
git add . 				#将当前目录所有文件添加到git暂存区
git add test0415.txt	#将test0415.txt文件添加到git暂存区
git commit -m "my first commit" #提交并备注提交信息
git push origin master #将本地提交推送到远程仓库
在gitee 可以看到test0415文件。

方法2、本地初始化一个仓库,设置远程仓库地址后再做push
git remote add origin [email protected]:happygrilclh/project.git / git remote add origin https://gitee.com/happygrilclh/project.git    
git add . 				#将当前目录所有文件添加到git暂存区
git commit -m "my first commit" #提交并备注提交信息
git push origin master #将本地提交推送到远程仓库

小结
要关联一个远程库,使用命令git remote add origin git@server-name:path/repo-name.git;
关联后,使用命令git push -u origin master第一次推送master分支的所有内容;
此后,每次本地提交后,只要有必要,就可以使用命令git push origin master推送最新修改;
分布式版本系统的最大好处之一是在本地工作完全不需要考虑远程库的存在,也就是有没有联网都可以正常工作,
而SVN在没有联网的时候是拒绝干活的!当有网络的时候,再把本地提交推送一下就完成了同步,真是太方便了!                  

 



 

Published 105 original articles · Like 30 · Visits 160,000+

Guess you like

Origin blog.csdn.net/happygrilclh/article/details/105542804