git远程仓库衍生产品
-
Github(国外最大的代码仓库)
-
Gitee(码云 阿里)
-
Coding(扣钉 腾讯)
-
Codehub(华为)
-
GitLab(开源的私有远程仓库)
码云远程代码仓库操作
新建仓库
简易的命令行入门教程:
# Git 全局设置:
git config --global user.name "1637991558"
git config --global user.email "1637991558@qq.com"
# 创建 git 仓库:
## 创建目录
mkdir code
## 进入目录
cd code
## 将目录初始化成git仓库
git init
--------------------------
touch README.md
git add README.md
git commit -m "first commit"
--------------------------
## 将远程仓库添加到本地的配置文件中
git remote add origin git@gitee.com:yumengw/code.git
## 删除远程仓库配置
git remote remove origin
## 将本地代码,推送到远程仓库
git push -u origin "master"
# 已有仓库?
cd existing_git_repo
git remote add origin git@gitee.com:yumengw/code.git
git push -u origin "master"
配置远程仓库的公钥
##生成公钥
[root@web01 code]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:cwl1U/6ziRQWholI7mjnUj50tjwCn/Gxa5V63FY7B+M root@web01
The key's randomart image is:
+---[RSA 2048]----+
| ... o =+. |
| .. o +.o. |
| .. o. |
| o . .. .. |
| + *S+o .. ..|
| . O Bo+o. +.+|
| . B *+ .o.=.|
| . oooo oEo.|
| ... . o|
+----[SHA256]-----+
## 查看
[root@web01 code]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/hq0PhPvNCHgBST2umBUTtAOl+wcfFsr06kl7JuoeoSvijTdA9+BOMiQujK+GQWdkYBXT8Y+xCSGUcHWaV9y5HIGTnRE1hcjqjj0PztV4Jy24Wo4pMdNS1YK/4cuXB/zBFNSJgjQa/bcvr4qe7MCDDr3It4NDhwErr0U6Ee1l5f2ujlRxSMfAAWGkpZisv/3u0mbeE3U/yWS2mOnyHl692m6CG3MHDY5DXZ3ui9eS7BL1dRcOpCBmbCuqS/H0xQe5iDZlYxiKLws9szF6uS6AJz19zVrW1U4K65+3bhs53kCvkZe+j3XckHmY+zqCKoki5xkDGwivDaX2mO7QyTuB root@web01
## 默认只推送代码
[root@web01 code]# git push -u origin "master"
Counting objects: 23, done.
Compressing objects: 100% (22/22), done.
Writing objects: 100% (23/23), 2.92 KiB | 0 bytes/s, done.
Total 23 (delta 8), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To git@gitee.com:yumengw/code.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
## 如果要把已经创建的分支都推送
[root@web01 code]# git push --all
Total 0 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To git@gitee.com:yumengw/code.git
* [new branch] ceo_branch -> ceo_branch
* [new branch] mishu_branch -> mishu_branch
第一次拉取代码
## 生成密钥
[root@web02 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:m25MSSKYLKbq0K6d13L347n8cd+SQikvyrELkwp+Mrs root@web02
The key's randomart image is:
+---[RSA 2048]----+
| |
| |
| . o |
|..+ . . . |
|o. . oS. . |
|.. .oo. o |
|o o .+o+ +. .. |
|o+oo+.o=++o.ooo..|
|ooEB.o o*=*=.. .o|
+----[SHA256]-----+
## 在Gitee中加入公钥
## 拉取(第一次拉取代码)
git clone url
[root@web02 ~]# git clone git@gitee.com:yumengw/code.git
Cloning into 'code'...
remote: Enumerating objects: 23, done.
remote: Counting objects: 100% (23/23), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 23 (delta 8), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (23/23), done.
Resolving deltas: 100% (8/8), done.
[root@web02 ~]# ll
total 4
-rw-------. 1 root root 1512 Apr 11 16:23 anaconda-ks.cfg
drwxr-xr-x 3 root root 68 Aug 23 20:25 code
url可以在配置文件里查看(配置文件在code下并不是在新建的拉取目录laqu下)
## 后续同步代码
[root@web01 code]# git pull
[root@web01 code]# git fetch -vp
From gitee.com:yumengw/code
= [up to date] master -> origin/master
= [up to date] ceo_branch -> origin/ceo_branch
= [up to date] mishu_branch -> origin/mishu_branch
git高级操作
## git 简化操作
[root@db01 code]# echo 'alias ga="git add"'>> ~/.bashrc
[root@db01 code]# echo 'alias gc="git commit -v"'>> ~/.bashrc
[root@db01 code]# echo 'alias gl="git pull"'>> ~/.bashrc
[root@db01 code]# echo 'alias gp="git push"'>> ~/.bashrc
[root@db01 code]# echo 'alias gco="git checkout"'>> ~/.bashrc
[root@db01 code]# echo 'alias gst="git status -sb"'>> ~/.bashrc
[root@db01 code]# source ~/.bashrc.
[root@db01 code]# alias glog="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
git大封印术
[root@web01 code]# vim index.html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>代码迭代过程</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="demo">澳门皇家DC</div>
<div id="demo2"></div>
<script src="main.js"></script>
<div>1</div>
<div>2</div> ## 新写了一些代码 没写完 不想提交 可以保存起来 后面再拿出来继续写
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</body>
</html>
# 放入暂存区
[root@web01 code]# git add index.html
# 1.将新代码,封印到卷轴
[root@web01 code]# git stash
# 2.通灵出来
[root@web01 code]# git stash pop
Comments | NOTHING