[Git Basics] Git installation configuration and basic concepts

1. Installation

1.1 Linux

On Linux, it is recommended that you install git in binary mode. You can use the basic package management tool included in the distribution to install it. If you are using the CentOS or Fedora operating system, you can use the yum command to install git:

sudo yum install git

If you are ubuntu or Debian, you can use the apt-get command to install git:

sudo apt-get install git

For more options, the official Git website has installation steps on various Unix flavors at http://git-scm.com/download/linux.

1.2 Windows

There are also several installation methods for installing Git on Windows. The official version can be downloaded from the official Git website. Open http://git-scm.com/download/win, it will automatically check whether your operating system is 32-bit or 64-bit, and start downloading the corresponding installation package.

Another easy way is to install GitHub for Windows. The installer includes both graphical and command-line versions of Git. It also supports Powershell, providing a stable credential cache and sanity wrapping settings. You can download it from the GitHub for Windows website at http://windows.github.com.

1.3 Mac

Method 1: Install git through homebrew

First homebrew: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install), install git:brew install git

Method 2: via xcode

Install Xcode directly from the AppStore, Xcode integrates Git, but it is not installed by default, you need to run Xcode, select the menu "Xcode" -> "Preferences", find "Downloads" in the pop-up window, select "Command Line Tools", click " Install" to complete the installation.

2. Configuration

The first thing you should do when installing Git is to set up your username and email address. This is important because every Git commit uses this information, and it's written to every commit you make, immutable:

git config --global user.name [你的昵称]
git config --global user.email [你的邮箱]

Again, if options are used --global, the command only needs to be run once, because Git will use that information for whatever you do on that system afterwards. --globalWhen you want to use a different user name and email address for a specific project, you can configure it by running the command without adding options in that project directory .

Many GUI tools will help you configure this information on first run.

You can also use git config --list to view all configurations of git.

If you need help using Git, there are three ways to find manuals for Git commands:

git help <verb>
git <verb> --help
man git-<verb>

For example, to get the manual for the config command, execute:

git help config

Of course, if you encounter problems, you can also check the official documentation of git: https://git-scm.com/book/zh/v2.

2. Basic concepts

Git is a version control system developed by Linus Torvalds to manage code in software development. The main function of Git is to record the historical changes of the code and manage different versions of the code. Let's talk about the basic concepts of Git:

  1. What is Git?

Git is a distributed version control system that can record every modification of the code, including who modified the code, when the code was modified, and what content was modified. Git stores all codes in a local warehouse, and each developer can modify and submit the code locally, and Git will automatically synchronize these modifications to the remote warehouse, thereby realizing multi-person collaborative development.

  1. What is Git good for?

Git can help development teams better manage code and avoid code conflicts and loss. Use Git to easily roll back code, view code history, compare different versions of code, and more. Git can also help developers work together. Different developers can modify and submit code locally, and Git will automatically synchronize these modifications to the remote warehouse, avoiding code conflicts and duplication of work.

  1. Why use Git?

Git is an open source, free, and efficient version control system that can help development teams better manage code and improve code quality and efficiency. Using Git can avoid code loss, conflicts, and duplication of work. At the same time, you can easily roll back code, view code history, and compare different versions of code. Git can also help developers work together better, improving team collaboration efficiency and code quality. Therefore, using Git is an essential part of modern software development.

  1. advantage
  • Version management has a central server that can save all codes, documents
  • Every modification can be submitted to the repository, and the modification is recorded and traceable
  • Don't be afraid that a colleague has left, and the code is not in the warehouse
  • After the local code is lost, it can be checked out from the repository
  • Multi-person collaboration, the work completed by each colleague is submitted to the repository for easy integration
  • Branch management can be pulled from the repository when we want to develop requirements or fix PRs
  • In large enterprises, each commit may trigger a build to check the quality of the code in real time
  • If the build fails, a commit can be automatically reverted

Guess you like

Origin blog.csdn.net/weixin_52665939/article/details/130043384