【git】git的一些基础操作

一.git下载

git下载地址:https://git-scm.com/downloads

二.git初次操作

1.生成公钥

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

之后本地生成文件,文件路径

windows:C:\Users\用户名\.ssh
linux:cd ~ 进入主目录

在这里插入图片描述
id_rsa.pub即为公钥,复制内容粘贴
在这里插入图片描述

2.修改全局用户名和邮箱地址:

git config --global user.name  "username"     
git config --global user.email "[email protected]" 

3.本地仓库关联远端仓库

git remote add origin ssh://[email protected]/weiyuting/shortLink.git

4.本地初始化

git init

5.将项目上所有的文件添加到本地仓库

git add .

6.提交到本地仓库

git commit -m "注释内容"

7.创建main分支

git checkout -b main

8.推送到main分支

git push origin main

9.拉取远端main分支

git pull origin main

三.git其他操作

1.develop分支

最好每次推送到develop分支,再请求合并到main分支

git checkout -b develop
git pull -r origin main   将main分支拷贝到本地
git add .
git commit -m "develop_test"
git remote add origin ssh://[email protected]/weiyuting/shortLink.git
git push origin develop
再做分支合并

2.查看分支

git branch   查看本地所有分支
git status  查看当前本地所在分支
git branch -r   查看远端所有分支
git branch -a  查看本地+远端所有分支

3.切换分支

git switch develop
git checkout develop

4.查看分支历史

git log

猜你喜欢

转载自blog.csdn.net/qq_45859826/article/details/130087059