常用配置
-
Git
的配置1.1 设置用户名和邮箱(
—global
为全局参数, 表明本地所有Git
仓库都会使用这个配置);$ git config --global user.name xxxx $ git config --global user.email xxx_email@xx.xxx
1.2 生成密钥(
SSH key
)$ ssh-keygen -t rsa -C xxx_email@xx.xxx
1.3 添加密钥
(SSH key)
,并验证是否成功添加密钥: 讲上一步骤生存的密钥 即
.ssh/id_rsa.pub
中内容全部复制,在github
的settings → SSH and GPG keys → New SSH key
, 中粘贴复制的内容(Title
自定义)验证:
github
输入第一条命令, 码云输入第二条$ ssh -T git@github.com $ ssh -T git@gitee.com
-
创建项目工程
2.1 远程仓库:在
github
中New repository
输入Repository name
[例如:TestDemo
]2.2 项目工程:在自己本地电脑上新建一个与
github
新项目工程同名的文件夹。[例如:TestDemo
] -
创建版本库
进入
步骤二
中的文件夹下,输入git init
命令初始化仓库,若出现:Initialized empty Git repository in E:/**/.git/
则表示创建成功[注意:此时会生成一个.git目录(隐藏目录)] -
连接远程仓库(下面两种方式都可以)
$ git remote add origin git@github.com:xxx.git $ git remote add origin https:xxx.git
-
从远程仓库pull文件(若远程仓库没有文件,直接执行
步骤六
)$ git pull origin master
-
将本地文件push到远程仓库(若没有文件则手动创建)
# 查看工作目录的状态
$ git status
# 将文件添加到暂存区
$ git add <file>
# 提交更改,添加备注信息(此时将暂存区的信息提交到本地仓库)
$ git commit -m "commnet"
# 将本地仓库的文件push到远程仓库(若 push 不成功,可加 -f 进行强推操作)
$ git push origin master
注: 至此已经完成了 远程与本地仓库的配置,若需要单独配置可见以下操作
额外拓展
生成多个密钥(多个账户)配置不同的远程仓库【账号配置为局部变量】
-
添加新的
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
-
配置config文件
在
./ssh
目录下若没有.gitconfig
文件则创建# 配置 github $ Host github.com $ HostName github.com $ IdentityFile C:\\Users\\xxx\\.ssh\\id_rsa_github PreferredAuthentications publickey User ZeroBound # 配置 gitee $ Host gitee.com $ HostName gitee.com $ IdentityFile C:\\Users\\xxx\\.ssh\\id_rsa_gitee PreferredAuthentications publickey User zhzw
-
到
github
或码云
上添加 密钥,之后验证是否成功$ .ssh -T git@github.com $ .ssh -T git@gitee.com
-
进入仓库目录配置用户名和邮箱
$ git config user.name "yourname" $ git config user.email "your_email@youremail.com"
相关问题
-
git pull origin master
无法进行pull
****,出现如下提示:-
第一种情况
$ git pull origin master fatal: unable to access 'https://github.com/yourName/Demo.git': error setting certificate verify locations: CAfile: G:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt CApath: none
分析:
ca-bundle.crt
文件是证书文件。根据提示CApath:none
没有该文件,所以无法访问远程仓库;**解决:**修改为正确路径 或者 将证书验证设置
false
$ git config --system http.sslcainfo E:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt $ git config --system http.sslverify false
-
第二种情况
fatal: refusing to merge unrelated histories
**解决:**如下操作即可解决
$ git pull origin master --allow-unrelated-histories
-
-
每次git push origin master 时都需要输入用户名和密码:
- 因为配置的时候使用的是https协议,所以每次都需要输入
$ git remote -v 查看远程连接 $ git remote rm origin 删除远程连接 $ git remote add origin git@github.com:xxx.git
-
git add .
时遇到LF will be replaced by CRLF in public/Editor/src/less/text.less.The file will have its original line endings in your working directory
解决:
$ git rm -r --cached . $ git config core.autocrlf false $ git add .
评论区