目录
安装Git
MAC 上安装Git主要有三种方式
首先查看电脑是否安装Git,终端输入:
git
安装过则会输出:
WMBdeMacBook-Pro:~ WENBO$ git
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<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
reset Reset current HEAD to the specified state
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
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
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
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.
1、通过homebrew安装Git
- 1、未安装homebrew,需安装homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 2、安装git
brew install git
2、通过Xcode安装
直接从AppStore安装Xcode,Xcode集成了Git,不过默认没有安装,你需要运行Xcode,选择菜单“Xcode”->“Preferences”,在弹出窗口中找到“Downloads”,选择“Command Line Tools”,点“Install”就可以完成安装了。
3.通过官网下载安装
下载链接 https://www.git-scm.com/download/
下载下来,下一步,下一步就好.
创建ssh key、配置git
1、设置username和email(github每次commit都会记录他们)
git config --global user.name "wenbo"
git config --global user.email "1050794513@qq.com"
2、通过终端命令创建ssh key
ssh-keygen -t rsa -C "1050794513@qq.com"
1050794513@qq.com
是我的邮件名,回车会有以下输出
Last login: Sat Jan 6 14:12:16 on ttys000
WMBdeMacBook-Pro:~ WENBO$ ssh-keygen -t rsa -C "1050794513@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/WENBO/.ssh/id_rsa):
/Users/WENBO/.ssh/id_rsa already exists.
Overwrite (y/n)? n
WMBdeMacBook-Pro:~ WENBO$
由于这里我原来已经创建过,这里我选n,没有创建过的,会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。
3、登录GitHub(默认你已经注册了GitHub账号),添加ssh key,点击Settings,如图
点击New SSH key,如图
添加key,如图
4、链接验证
ssh -T git@github.com
终端输出结果
Last login: Sat Jan 6 14:42:55 on ttys000
WMBdeMacBook-Pro:~ WENBO$ ssh -T git@github.com
Hi wenmobo! You've successfully authenticated, but GitHub does not provide shell access.
WMBdeMacBook-Pro:~ WENBO$
说明已经链接成功。
git 卸载
查看Git安装位置
which -a git
mac上默认安装的git安装在
/usr/bin/git
彻底删除:
cd /usr/bin
sudo rm -rf git*
安装有其他版本的git卸载方式也一样,进入安装目录,管理员权限删除。