Git使用教程(二) — Git安装和使用

Git使用教程(二) — Git安装和使用

使用目的:通过git管理github托管的项目代码

一、下载安装

  1. GIt官网下载:https://www.git-scm.com/download/win
    或者https://gitforwindows.org
    在这里插入图片描述

  2. 双击安装
    在这里插入图片描述

  3. 选择安装的工作目录
    在这里插入图片描述

  4. 选择组件
    在这里插入图片描述

  5. 开始菜单目录名设置
    在这里插入图片描述

  6. 选择使用命令行环境
    在这里插入图片描述

  7. 以下三步默认,直接点击next
    在这里插入图片描述

  8. 等待安装
    fg
    在这里插入图片描述

  9. 检验是否安装成功
    ff

二、 Git基本工作流程

  1. Git工作区域
    gz
  2. 向仓库中添加文件流程
    在这里插入图片描述

三、Git初始化及仓库创建和操作

  1. 基本信息设置
    设置用户名: git config --global user.name 'William-github-hub'
    设置用户名邮箱: git config --global user.email '3050845604@qq.com'
    查看设置:git config --list
    在这里插入图片描述
    注:该设置在github仓库主页显示谁提交了该文件(--global 参数,有了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然你也可以对某个仓库指定的不同的用户名和邮箱)

  2. 初始化一个新的Git仓库
    创建文件夹
    在这里插入图片描述
    在文件内初始化git(创建git仓库)
    使用cd Firstgit init命令
    在这里插入图片描述

  3. 向仓库添加文件
    创建a1.c文件到工作目录:touch a1.c
    在这里插入图片描述
    添加a1.c到暂存区:git add a1.c
    在这里插入图片描述
    添加a1.c到仓库:git commit -m 'add a1.c'
    在这里插入图片描述

  4. 修改仓库文件
    在这里插入图片描述
    在这里插入图片描述
    b

  5. 删除仓库文件
    在这里插入图片描述

四、Git管理远程仓库

  1. 使用远程仓库
    使用目的:备份,实现代码共享集中化管理
    在这里插入图片描述
  2. Git克隆操作
    目的:将远程仓库(github对应的项目)复制到本地
    获得仓库地址:
    在这里插入图片描述
    使用git clone +仓库地址进行克隆操作
    f
  3. 将本地仓库同步到git远程仓库中
    使用git push命令
    在这里插入图片描述
    添加成功
    在这里插入图片描述
    不想重复输入用户名和密码,将.git/config文件进行修改
[remote "origin"]  
    url = https://github.com/用户名/仓库名.git
修改为:
[remote "origin"]
    url = https://用户名:密码@github.com/用户名/仓库名.git

在这里插入图片描述

五、优化使用

我们可以添加如下设置来优化我们git的使用

git config --global user.name "william"
git config --global user.email 472853046@qq.com
git config --global color.ui true
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.br branch
git config --global alias.l "log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
git config --global alias.ll "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值