Git installation and simple use

1. Installation

Mac comes with Git

homebew installation (computer installation HomeBrew)

brew install git# 查看安装版本git version  

Download Git from the official website https://git-scm.com/downloads

2. Basic configuration

git config --global user.name "Your Name"  #用户名git config --global user.email "[email protected]"  #邮箱# 查看信息git config -l 

3. Basic concepts

1. Warehouse

Create a new folder, and enter the directory from the terminal, execute , and then a hidden file git initwill appear in the directory , indicating success.git

2. Workspace

The directory where git init is executed is the workspace. All files are first created in the workspace and then stored in the warehouse (repository) for version control.

3. Temporary storage area

The temporary storage area is also in the .git directory. When the files in the workspace enter the warehouse, they must first enter the temporary storage area.

4. branch

Version control, simply put, is to record many versions of files, and the branch is the final recording location of these versions

4. Basic operation

1. Check warehouse status

Execute git status to see the status of the files in the workspace

view status 1

2 Temporary files

git add .Save all the files in the workspace to the temporary storage area

temporary file

3 Submit documents

Execute git commit -m "write the description information of the submission here" to store the files in the temporary storage area into the branch to form a version

Submit documents

5 Connect to remote warehouse

Take code cloud ( https://gitee.com/ ) as an example, (GitHub is the same)

1 Secret key & public key

1> View the secret key (ssh key)

cat ~/.ssh/id_rsa.pub

2> Create SSH Key

ssh-keygen -t rsa -C “[email protected]

image-20221227213714093

Press Enter directly and do not enter the 123456 password. Just press Enter 3 times. Do not enter the password

If all goes well, you can find the .ssh directory in the user's home directory. There are two files id_rsa and id_rsa.pub in it. These two are the secret key pair of SSH Key. id_rsa is the private key and cannot be leaked out. id_rsa.pub It is the public key, you can tell anyone with confidence.

image-20221227213852573

3> Log in to github or gitee, enter Settings - SSH public key, fill in the content of the public key id_rsa.pub file in the text box

image-20230218185607345

2 Create a new remote warehouse

Create remote warehouse 2

Create remote warehouse 3

3 Local associated remote warehouse

Associate remote warehouse


Basically not used, idea, vscode and other software are integrated with git, you can also use third-party software such as: sourcetree, TortoiseGit (Windows only)

Guess you like

Origin blog.csdn.net/qq_55881671/article/details/129104261
Recommended