Git基础教学1——安装、环境配置与基本设置
Git基础教学1——安装、环境配置与基本设置
下载Git
点击进入Git官网选择自己电脑的操作系统安装
之后进行傻瓜式安装(如果有需要更换下载路劲的自行更换),一直点下去即可。
安装成功后在根目录下运行git-bash.exe或者运行根目录下bin文件夹中的bash.exe或者鼠标右击选择Git Bash Here就可以开始使用命令。
配置变量环境
右击此电脑(我的电脑)——属性——高级系统设置——环境变量——系统变量——Path——新建——把安装Git根目录下bin的路劲写入新建保存。
win+r输入cmd打开命令窗口输入git,有如下界面即配置成功。
C:\Users\HP>git usage: git [--version] [--help] [-C <path>] [-c <name>=<value>] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] [--super-prefix=<path>] [--config-env=<name>=<envvar>] <command> [<args>] These are common Git commands used in various situations: start a working area (see also: git help tutorial) clone Clone a repository into a new directory init Create an empty Git repository or reinitialize an existing one work on the current change (see also: git help everyday) add Add file contents to the index mv Move or rename a file, a directory, or a symlink restore Restore working tree files rm Remove files from the working tree and from the index examine the history and state (see also: git help revisions) bisect Use binary search to find the commit that introduced a bug diff Show changes between commits, commit and working tree, etc grep Print lines matching a pattern log Show commit logs show Show various types of objects status Show the working tree status grow, mark and tweak your common history branch List, create, or delete branches commit Record changes to the repository merge Join two or more development histories together rebase Reapply commits on top of another base tip reset Reset current HEAD to the specified state switch Switch branches tag Create, list, delete or verify a tag object signed with GPG collaborate (see also: git help workflows) fetch Download objects and refs from another repository pull Fetch from and integrate with another repository or a local branch push Update remote refs along with associated objects 'git help -a' and 'git help -g' list available subcommands and some concept guides. See 'git help <command>' or 'git help <concept>' to read about a specific subcommand or concept. See 'git help git' for an overview of the system.
在cmd中输入bash就可以开始使用命令。
C:\Users\HP>bash HP@LAPTOP-JQ25M9AN MINGW64 ~ $
基本配置
打开Git Bash
设置用户信息
git config --global user.name "你的用户名" git config --global user.email "你的邮箱"
查询用户信息
git config --global user.name git config --global user.email
或者
git config -l //查看user.name和user.email
为常用指令设置别名(可以不设置)
有些常用指令参数非常多,每次都要输入好多参数,我们可以设置别名。
打开用户目录,创建.bashrc文件。
部分windows系统不允许用户创建点号开头的文件,可以使用命令touch ~/.bashrc
解决。
在.bashrc文件中输入如下内容。
#用于输入git提交日志 alias git-log='git log --pretty=oneline --all --graph --abbrev-commit' #用于输出当前目录所有文件及基本信息 alias ll='ls -all'
打开GitBash,执行source ~/.bashrc
解决GitBashn乱码问题(不输入中文不用出现问题)
打开GitBash执行git config --global core.quotepath false
在安装Git的目录下/etc/bash.bashrc文件最后加入两行
export LANG="zh_cn.UTF_8" export LC_ALL="zn_cn.UTF_8"
Git常用命令(基本的linux命令)
查看当前目录:ls/ll(配置过别名可以使用)
查看文件内容:cat
创建文件:touch
使用vi编辑器:vi
桌面右击Git GUI Here是GitGUI(git自带图形化界面)