新建一个gitlab项目,并且上传本地项目

第一步、项目目录下右键,选中 git bash here

第二步,命令git init,目录下就会生成一个.git 目录

ls -a 查看是否创建,可以看出创建完成

 

 第三步,命令 git add .  表示将当前目录下所有文件纳入git版本控制

 如果当前目录有多个文件,可以将 . 换成文件名指定文件

 第三步,命令提交:git commit -m "注释语句",提交到本地仓库

 第四步、在gitlab上新建一个项目,然后clone with HTTP,  地址https://gitlab.com/xxxx/xxx.git

第五步、命令git remote add origin https://gitlab.com/xxxx/xxx.git 本地仓库和远程仓库关联

第六部、命令 git push -u origin master 输入账号和密码即可

最后注意,这时候提交代码的时候有可能不成功,这时候就需要执行以下命令

命令 git pull https://gitlab.com/xxxx/xxx.git master --allow-unrelated-histories,

注意--后面表示允许不相干的两个仓库合并,因为我们之前两个仓库是完全独立的,所以直接是没办法pull下来,需要加上后面参数才行

 注意有可能出现的问题

1)fatal: remote origin already exists. 翻译过来就是:致命:远程来源已经存在

git remote -v 查看远程库信息

解决办法如下:
1、先输入git remote rm origin(删除关联的origin的远程库)
2、再输入git remote add origin https://gitlab.com/xxxx/xxx.git 就不会报错了!

2)fatal: Couldn't find remote ref master  

1、检查本地git配置 git config user.name、git config user.email

2、git remote -v 查看是否有远程库,有就删掉 git remote rm origin

3)fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决办法如下:
git remote add origin https://gitlab.com/xxxx/xxx.git

4) 某些特殊的文件无法提交上去,或者提交报错

The following problems have occurred when adding the files:

The following paths are ignored by one of your .gitignore files:serer/nacos-serer/binhint:

Use -f if you really want to add them.hint: Turn this message off by runninghint: "git config advice.addlgnoredFile false’

解决办法:git add -f 文件夹/文件名

 

 

posted @ 2021-03-26 16:55  cheFly  阅读(416)  评论(0编辑  收藏  举报