1、git init 初始化仓库
场景:创建新仓库
git init
git remote add origin git@gitee.com:snail-kk/fistOrigin.git
git remote -v
git remote rm name
2、将本地仓库的内容分别推送到两个远程仓库
远程仓库1的地址(SSH)为:git@gitee.com:snail-kk/git.git
远程仓库2的地址(SSH)为:git@gitee.com:snail-kk/note-picture.git
在F盘下创建一个localstore文件夹用做仓库
![1645597425380](https://img-blog.csdnimg.cn/img_convert/cb109e1e3c673a41778bf3cb6cd6e8ff.png)
打开Git Bash cd到此路径下
![1645597536724](https://img-blog.csdnimg.cn/img_convert/75cc888387a7bc03165f734f70d7fe10.png)
**初始化仓库。**初始化仓库后,localstore里会有一个.git文件夹。表示localstore是一个git仓库,.git文件夹里有仓库的相关信息。
![1645597626158](https://img-blog.csdnimg.cn/img_convert/2b348d6f23b7f85fc0ba867c5c0614b0.png)
分别与远程仓库1和远程仓库2建立连接。别名分别为origin1和origin2
![1645597944663](https://img-blog.csdnimg.cn/img_convert/aa3c09dc87fc2828060ca995dce2e7ce.png)
查看本地仓库所连接的远程仓库的信息
![1645597995782](https://img-blog.csdnimg.cn/img_convert/59e45f103250955afd963ec0dd635476.png)
创建a.txt文件并提交
![1645598119516](https://img-blog.csdnimg.cn/img_convert/7d4adecf131f953f47fdf230c5af0f68.png)
将a.txt分别推送到两个远程仓库。
推送前两个远程仓库都为空
![1645598254183](https://img-blog.csdnimg.cn/img_convert/940c9988f9769dc74c64e9ab98242283.png)
![1645598270336](https://img-blog.csdnimg.cn/img_convert/300c60cd99ec2321291f4d5387b2ebd5.png)
推送
(如果这一步报错,请看后面的注意)
![1645599549300](https://img-blog.csdnimg.cn/img_convert/41fb60cca27f92168dbd3e0ad3905a4d.png)
![1645600518998](https://img-blog.csdnimg.cn/img_convert/535b90fc9bfb727c504c84ade2057b8d.png)
推送后
![1645600615210](https://img-blog.csdnimg.cn/img_convert/1cf39707da656eb2675edc1851fe02b9.png)
![1645600640484](https://img-blog.csdnimg.cn/img_convert/5e0480b0ad037b042f67cce5be75fe9b.png)
注意:如果远程仓库不是新建立的,先做拉取操作
git pull origin1 master
git pull origin1 master --allow-unrelated-histories
我在对origin2做操作的时候就遇到了问题
![1645600458912](https://img-blog.csdnimg.cn/img_convert/a9a1e2fe92cf96053ac73c0e48b4cb97.png)
3、git clone 克隆仓库
相比git init操作,git clone会直接将远程仓库内容拉取到本地,相当复制了一份远程仓库。
在F盘下创建localstore2,在此目录下,操作如下:
![1645601075802](https://img-blog.csdnimg.cn/img_convert/5822f53f46b90fae4d05e67638d19f80.png)
默认别名为origin
更改仓库名
git remote rename old_name new_name
![1645601269833](https://img-blog.csdnimg.cn/img_convert/be1c8eae51cfe02d72e6a874d92c3711.png)
4、git add
命令 | 含义 |
---|
git add 文件名 | add单个文件 | git add . | 提交被修改的和新建的文件,但不包括被删除的文件 | git add -u --update | 更新所有改变的文件,即提交所有变化的文件 | git add -A --all | 提交已被修改和已被删除文件,但是不包括新的文件 |
5、git commit
命令 | 含义 |
---|
git commit -m ‘提交信息’ | 提交 | git commit -a -m ‘提交信息’ | 可以把还没有执行add命令的修改一起提交 | | |
6、SSH配置 (公钥秘钥)
? 基于Git的开发,可采用HTTP或SSH两种方式进行代码的下载和上传。当选择SSH方式时,需要本地配置SSH公钥密钥对。将私钥保存值本地,公钥保存至Gitlab中,以下为配置过程:
? 1.双击Git Bash图标,进入Git Bash命令窗口
![1645602479323](https://img-blog.csdnimg.cn/img_convert/02080a29e5e42f2f6e6e05c889d18eb6.png)
? 2.生成SSH公钥密钥对,参考命令如下:
ssh-keygen -t rsa -b 2048 -c "username@cfit.cn"
![1645602956340](https://img-blog.csdnimg.cn/img_convert/5e1356c1a94e7a173f6bb3d818cf4c5e.png)
? 3.查看SSH公钥并复制到gitlab服务器。默认公钥保存路径~/.ssh/id_rsa.pub,可用入刑命令查看公钥内容(或可直接用文本文件方式打开id_rsa.pub):
cat ~/.ssh/id_rsa.pub
? ![1645603000588](https://img-blog.csdnimg.cn/img_convert/20d0a6a4cd3ffc0053aae9231e5bf7c1.png)
? 复制并粘贴公钥内容到GitLab账户中的SSH public key栏内,详见文档《gitlab使用手册》。至此,本地配置SSH已成功。
2.2设置用户名邮箱
? 1.设置用户名密码
git config -global user.name "username"
git config -global user.email "username@cfit.cn"
![1645603038217](https://img-blog.csdnimg.cn/img_convert/8962c30d61447c1c243267a08a476a66.png)
? 2.查看git设置是否生效
git config -l
7、解决冲突
<<<<<<< HEAD
本地代码
=======
拉取的代码
>>>>>>> 04eedo87sodkfj987w423ks9
等号上半部分为我们本地代码
等号下半部分为拉取的代码
保留正确需要的,将不需要的代码删掉,同时,冲突标签也删掉,将解决好冲突的文件add、commit后即可。
|