在gitlab新建空项目,将本地的git仓库的内容上传

时间:2023-03-09 20:30:27
在gitlab新建空项目,将本地的git仓库的内容上传

gitlab新建了这个项目。

按照官网的步骤上传代码

一:将本地代码上传到本地仓库

  1.进入项目文件夹

  git init

  2.项目代码添加到本地git  

git add .

  3.提交到stage区域

git commit -m "这次同步的内容"

二:本地仓库连接远程gitlab地址

  1.连接gitlab的项目地址

git remote add origin https://gitlab.com/xxxxxx/xxxxxx.git

   2.上传本地代码

git push -u origin --all

  3.如果打了tag,上传tag

git push -u origin --tags

  

———————————————————设置———————————————————————————

1.安装之后设置用户名和邮箱

git config --global user.name "xxx"
git config --global user.email "xxx"

 

————————————————————ssh—————————————————————— 

[root@iZwz94d6ox6sdexe984lpuZ ~]# git config --global user.name "yindongzi"
[root@iZwz94d6ox6sdexe984lpuZ ~]# git config --global user.email "350343754@qq.com"
[root@iZwz94d6ox6sdexe984lpuZ ~]# cd /root/.ssh
[root@iZwz94d6ox6sdexe984lpuZ .ssh]# cat id_rsa.pub
ssh-rsa ……………………

  

生成密钥对:

ssh-keygen -t rsa -C "350343754@qq.com"

  

复制公钥的内容,粘贴到github。

然后在pc端登陆github

[root@iZwz94d6ox6sdexe984lpuZ .ssh]# ssh git@github.com
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi ZhzhIn! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

  

——————————————命令————————

---git文件流:workspace-stage-master

git status
#git checkout -xxx 撤销工作区的修改
git diff
#修改内容: 工作区修改 git add (临时仓库-stage)
#git reset 撤销临时仓库的修改
git status git commit(提交到仓库-master)
#git reset --hard HEAD^ 返回上一版本,^个数代表上几个存档
git push () git log
git push 推到对应的服务器(添加了ssh公钥的服务器)

—————————————rebase———————————  

合并status中的代码记录

git rebase  -i (对应代码版本的id)

  

git branch  dev#创建分支
git checkout dev#切换分支
git merge dev#把分支合入master ,当前处于master时才能合入其他分支

  _______________git remote_____________

git remote add originName xxxx.git 加载远程仓库的代码到本地
git branch 查看当前用户的branch
git branch -a 查看该项目的branch
git pull 把远程的master代码拉下来
# 处理冲突
git commit -a -m "fix"
git checkout master 切换到master分支
git merge remote/originName/HEAD 合并分支 git push 传到自己的远程仓库,github可以看到修改
git status 检查一下

  

————————常规操作——————————

git remote add other xxx.git
git fetch other master
git merge remote/other/master
git commit -a -m