mac中git的使用和初始化

这是我参与11月更文挑战的第20天,活动详情查看:2021最后一次更文挑战

前言

Git是我们在进行多人合作中经常使用的工具下面让我们来简单的说明一下在Mac端的安装和使用。

安装Git

1、浏览器搜索git,进入官网

image-20211121120009926

2、点击下载

image-20211121120147507

3、官方提供了几种下载方式(我们使用第一种)

image-20211121121416414

4、如果没安装Homebrew先安装Homebrew

1
arduino复制代码https://brew.sh/index_zh-cn

image-20211121121715427

5、然后安装Git

1
ruby复制代码$ brew install git

6、检查是否安装成功

1
ruby复制代码$ git

安装成功后会显示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
sql复制代码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
sparse-checkout Initialize and modify the sparse-checkout

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.

初始化Git

1、打开终端,创建一个文件夹(如:testGit)作为Git本地仓库,并使用cd 命令进入该文件夹

1
bash复制代码cd /Users/username/Desktop/testGit

2、使用命令,创建 .git目录

1
csharp复制代码git init

image-20211121124307723

3、使用命令设置用户名和邮箱

1
arduino复制代码git config --global user.name "username"
1
css复制代码git config --global user.email useremail@qq.com

4、查看Git配置

1
lua复制代码git config --l

本文转载自: 掘金

开发者博客 – 和开发相关的 这里全都有

0%