git常用操作

1、基本操作

配置用户名

git config --global user.name "liuzhihao"

配置邮箱

git config --global user.email "cn_liuzhihao@163.com"

生成公钥和私钥
ssh-keygen -t rsa -C "cn_liuzhihao@163.com"
按3次Enter
查看公钥
cat ~/.ssh/id_rsa.pub

git基础
1、git commit
2、git branch
3、git merge
4、git rebase

2、git创建初始化版本库

git init

3、git添加远程仓库

语法:git remote add origin 地址

notes:origin是源

git remote add origin git@codeup.aliyun.com:60f12451342aa6e0763abde9/deyu-alcloud.git
git remote add origin https://codeup.aliyun.com/60f12451342aa6e0763abde9/deyu_pro.git

查看当前查看地址

方法一

git remote -v

方法二

git remote show origin

4、从远程仓库pull文件

git pull origin master

5、git将本地代码推送到远程仓库

git status          查看工作目录的状态

git add <file>        将文件添加到暂存区

git commit -m "commnet"   提交更改,添加备注信息(此时将暂存区的信息提交到本地仓库)

git push origin master    将本地仓库的文件push到远程仓库(若 push 不成功,可加 -f 进行强推操作

 六、生成多个Key

a.添加新的ssh-key
如果报错:Could not open a connection to your authentication agent.无法连接到ssh agent;可执行ssh-agent bash命令后再执行ssh-add命令
  ssh-add ./id_rsa_github
  ssh-add ./id_rsa_gitee
 
b.配置config文件
在./ssh目录下若没有 config文件则创建
# 配置 github
Host github.com
HostName github.com
IdentityFile C:\\Users\\zzw\\.ssh\\id_rsa_github
PreferredAuthentications publickey
User ZeroBound

# 配置 gitee
Host gitee.com
HostName gitee.com
IdentityFile C:\\Users\\zzw\\.ssh\\id_rsa_gitee
PreferredAuthentications publickey
User zhzw
 
c.到github或码云上添加 密钥,之后验证是否成功
  1.ssh -T git@github.com
  2.ssh -T git@gitee.com
 
d.进入仓库目录配置用户名和邮箱
  git config user.name "liuzhihao"
  git config user.email "cn_liuzhihao@163.com"

  

资料来源:

https://www.cnblogs.com/zeo-to-one/p/8367801.html

https://www.cnblogs.com/syp172654682/p/7689328.html
https://oschina.gitee.io/learn-git-branching/

原文地址:https://www.cnblogs.com/zhanqing/p/git.html