$git pull origin master --allow-unrelated-histories
可以允许不相关历史提,强制合并,
添加配置 user.name 后面的名称随便写,user.email 后面是邮箱地址
[root@yoyo sbin]# git config --global user.name "root"
[root@yoyo sbin]# git config --global user.email "1171901273@qq.com"
[root@yoyo sbin]# git config --list
user.name=root
user.email=1171901273@qq.com
新建一个本地文件夹,cd进去,然后 init建仓
[root@yoyo ~]# mkdir /usr/local/git_code
[root@yoyo ~]# cd /usr/local/git_code/
[root@yoyo git_code]# git init
Initialized empty Git repository in /usr/local/git_code/.git/
在git_code目录,放需要上传的代码,比如新建一个test.py文件,随便写几行代码
[root@yoyo git_code]# vim test_yo.py
# 编辑python代码,写个print("hello world!")
# :wq保存退出
提交代码到本地仓库git add * (*是提交当前文件夹下全部的,也可以指定提交一个文件如:test.py)
[root@yoyo git_code]# git add *
查看仓库状态 git status
[root@yoyo git_code]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: test_yo.py
#
代码提交到缓存区 git commit -m "描述"
[root@yoyo git_code]# git commit -m "add test.py"
提交到远程仓库
[root@yoyo git_code]# git remote add origin http://47.104.x.x:8100/root/yoyo.git
最后一步push推送过去,push的时候,会让你输入账号和密码,这里的用户名和密码就是gitlab上注册的用户了
[root@yoyo git_code]# git push -u origin master
Username for 'http://47.104.x.x:8100': root
Password for 'http://root@47.104.x.x:8100':
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 257 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://47.104.x.x:8100/root/yoyo.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
推送成功后,打开gitlab后台,会发现已经有一次成功的提交了