git 上传文件到gitlab

1.登录

首先进入需要上传的文件夹,鼠标右键点击Git Bash Here

#输入用户名、邮箱
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
//查看设置
git config --list

2.生成公共密钥

ssh-keygen -t rsa -C "[email protected]"

生成密钥的位置在:

C:\Users\Administrator\.ssh

在这里插入图片描述

打开 id_rsa.pub,复制密钥,粘贴到下图中,点击增加密钥。

在这里插入图片描述

3.配置路由到hosts文件

当你出现报错:

ssh: Could not resolve hostname xxx.com: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

在这里插入图片描述

解决:
在C:\Windows\System32\drivers\etc中,配置hosts文件
右击hosts文件,并以记事本格式打开。然后在文件最后一行添加如下内容:
xxx.xxx.xxx github.com

4.初始化

输入git init,初始化git相关配置文件

git init

5、设置本地与远程仓库的链接

输入git remote add origin *你的远程仓库地址*,设置本地与远程仓库的链接

git remote add origin http://gitlabxxxxx.git

如果不设置会出现:

fatal: 'origin' does not appear to be a git repository fatal: Could not read from remote repository.

6、拉取远程仓库

输入git pull origin master,将远程仓库进行下拉,获取同步

git pull origin master

7、添加上传文件

输入git add . ,将所有文件添加

git add .

8、暂存文件

输入git commit -m “add new file”,提交代码

git commit -m “add new file”

9、提交暂存文件到指定分支

输入git push origin master,将代码上传至远程仓库的master节点

git push origin master

猜你喜欢

转载自blog.csdn.net/qq128252/article/details/127120175