1、安装Git
官网下载速度慢,下载不下来
阿里云下载地址:https://npm.taobao.org/mirrors/git-for-windows/
安装时windows编辑器选择 notepad++,linux选择vim 即可
2、设置姓名和邮箱及命令行输出颜色
git config --global user.name "Mike"
git config --global user.email "z_runwei@163.com"
git config --global color.ui auto
// 查看所有配置信息
git config -l


3、Git工作区域
Git本地有3个工作区域:工作目录(working directory)、暂存区(stage/index)、资源库(repository),加上远程的git仓库(remote directory),就是4个工作区域


4、Git仓库创建
4.1、本地仓库创建
git init
4.2、远程仓库创建
git clone 远程仓库url
5、忽略文件

6、配置 SSH秘钥,免密登录
// 生成 .pub 等文件
ssh-keygen -t rsa

将 .pub文件内容拷贝进 Gitee 设置里面的 SSH公钥里即可

7、Idea整合Git
7.1、在Gitee上新建项目,然后在本地clone一下。
git clone 项目url
7.2、在Idea上新建项目,并把上面生成的 .git等文件夹 拷贝到项目目录下,即可看到项目中文件的颜色变化。点击工具箱的 提交 按钮,即可提交代码到本地仓库

在项目目录的控制台输入:git push ,将代码推送到远程gtiee仓库中
7、常用的git命令
// 查看git所有配置信息
git config -l
// 复制远程项目到本地
git clone 远程仓库url
// 查看文件状态信息
git status filename
git status .
// 将文件添加到暂存区
git add .
// 将文件提交到本地仓库
git commit -m "提交的信息"
// 将文件推送到git远程仓库中
git push
// 生成 .pub 等秘钥文件
ssh-keygen -t rsa
// 查看项目分支
git branch
// 新建项目分支
git branch branch-name
// 删除项目分支
git branch -d branch-name
// 合并分支到当前分支
git merge branch-name
网友评论