前言
本文章所展示的如何Git安装与配置的具体步骤,第一次在CNDS上发布处女文章 (有点小激动),如有做的不足的地方还请大佬们指正。
Git是一个分布式版本控制软件,最初由林纳斯·托瓦兹创作,于2005年以GPL发布。
Mac上 Git下载有两种方式
1. 直接安装
https://git-scm.com/download/mac
click here to download manually
跳转到下载页面,等待五秒钟后就会跳出下载文件目录,如果没反应的话直接复制该网址https://sourceforge.net/projects/git-osx-installer/
单击Download跳转到下载页面.dmg
文件打开。由于是在网站上下载的,需要获取本地的信任~~(疯狂吐槽)~~ 单击左上角苹果图标
,选择系统偏好设置
,进入安全与个人隐私
git
命令,如果出现一下内容即安装成功$ git
MacBookdeMBP:~ macbookpro$ 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>]
<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 ' or 'git help '
to read about a specific subcommand or concept.
2. 用homebrew指令下载1**
homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git
1. 用户账号信息
$ git config --global user.name "Your Name" //其中Your Name即是你的GitHub账号
$ git config --global user.email "[email protected]" //其中[email protected]即是你GitHub账号绑定的邮箱
git config --list
指令查看Git的配置信息。$ git config core.ignorecase false
2. 生成公钥/密钥(ssh key)
$ ssh-keygen -t rsa -C "[email protected]"
MacBookdeMBP:~ macbookpro$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/macbookpro/.ssh/id_rsa):
/Users/macbookpro/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/macbookpro/.ssh/id_rsa.
Your public key has been saved in /Users/macbookpro/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:sjlsPFZ4TngGjUwio/cnRm1xLrzZzpSgbTjTxBCgtd0 1127551356@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| 不用复制我这个哈 |
| 单纯给你们看一下 |
|o o o E o |
| . o B X . |
| O @ S |
| . O # |
| X + |
| o o |
| |
+----[SHA256]-----+
如果没有创建过的,会要求确认路径和输入密码,使用默认的路回车就行
~/
下生成.ssh
文件夹$ cat .ssh/id_rsa.pub//使用cat命令查看生成的密钥
$ vim .ssh/id_rsa.pub
复制完好后输入Shift + zz 退出vim模式
部分Mac系统没有安装编辑器,输入open .ssh/id_rsa.pub命令可能打不开该文件。
3. 远程存储库添加密钥
Settings
–>再次单击SHH and GPG keys
–>最后单击New SSH Key
,在Title
输入你的标题,在Key
中输入刚刚复制的密钥4. 链接认证
$ ssh -T git@github.com
MacBookdeMBP:~ macbookpro$ ssh -T git@github.com
Enter passphrase for key '/Users/macbookpro/.ssh/id_rsa':
Hi chang-dian! You've successfully authenticated, but GitHub does not provide shell access.
1. 在GitHub上新建一个 Start a Project 项目
2. 远程下载项目到本地
[email protected]:用户名/项目名称.git
$ cd /Users/主机账户名/Desktop/ //主机账户名也就是你现在用的电脑的用户名
$ git clone git@github.com:用户名/项目名称.git //粘贴刚刚的创建项目的链接
本次演示的项目链接:[email protected]:chang-dian/Hello-World.git
回车,提示输入密码,认证成功后自动下载文件,终端完整输入如下
MacBookdeMBP:Hello-World macbookpro$ git clone git@github.com:chang-dian/Hello-World.git
Cloning into 'Hello-World'...
Enter passphrase for key '/Users/macbookpro/.ssh/id_rsa':
remote: Enumerating objects: 13, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 13 (delta 1), reused 8 (delta 1), pack-reused 0
Receiving objects: 100% (13/13), done.
Resolving deltas: 100% (1/1), done.
这时项目文件已经下载到桌面了。
3. 新建一个文件(我用的是VS code),保存的路径到克隆下来的Hello-World文件夹下
4. 在终端切换到你要提交的项目的目录(请切换到你的项目实际目录位置)
$ cd /Users/macbookpro/Desktop/Hello-World/
5. 把项目提交到git上
1.$ git init //git初始化,创建一个empty Git repository
2.$ git add . //添加当前目录及其中所有子目录及文件(.代表提交所有文件)
3.$ git commit -m "新建项目" //提交到本地仓库
4.$ ggit push //推送到远程仓库
MacBookdeMBP:Hello-World macbookpro$ git commit -m '新建READMD'
[master cf89df4] 新建READMD
1 file changed, 1 insertion(+)
create mode 100644 README.md
MacBookdeMBP:Hello-World macbookpro$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 374 bytes | 374.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/chang-dian/Hello-World.git
6bf3278..cf89df4 master -> master
内容出处:https://blog.csdn.net/xiaohanluo/article/details/53214933 ↩︎