Git教程

Git安装

Linux

  1. 先尝试输入git,看有没有安装git
  2. 如没有安装

安装步骤

wget https://www.kernel.org/pub/software/scm/git/git-2.9.4.tar.gz

tar -xvf git-2.9.4.tar.gz

cd git-2.9.4

./config –prefix=/usr/local/git2.9.4

make
make install

Mac

  1. 安装Homebrew
  2. brew install git

Windows

从https://git-for-windows.github.io下载msysgi

Git设置

  • system 存放到/etc/gitconfig 文件
    git config --system user.name "Your Name"
    git config --system user.email "email@example.com"

  • global 存放到~/.gitconfig 文件
    git config --global user.name "Your Name"
    git config --global user.email "email@example.com"

Git工作区和暂存区

常用命令

  • 获取远程库
    git clone url

  • 查看变更信息
    git status

  • 查看分支
    git branch 查看本地分支
    git branch -r 查看远程分支

  • 创建本地分支
    git branch 分支

  • 删除本地分支
    git branch -D 本地分支

  • 添加文件
    git add .

  • 提交
    git commit -m "XXXXX"

  • 撤消工作区修改
    git checkout --file

  • 切换分支
    git checkout 分支

  • 拉取远程分支并创建本地分支
    git checkout -b 本地分支名x origin/远程分支名x【使用该方式会在本地新建分支x,并自动切换到该本地分支x。】
    git fetch origin 远程分支名x:本地分支名x【使用该方式会在本地新建分支x,但是不会自动切换到该本地分支x,需要手动checkout】

  • 推送文件到远程仓库
    git push

  • 拉取
    git pull

原文地址:https://www.cnblogs.com/yoyoyang/p/11813989.html