Introduction to Git

Git is a distributed version control system

1.1 Centralized VS Distributed:

  1. Centralized version control system, version libraries are centrally stored in a central server, must be connected to the Internet to work, there is no historical version library.
  2. Distributed version control systems, where there is no “central server” for a version control system, there is a complete version library on everyone’s computer.
  3. Distributed system advantages: Higher security, no networking required, and if the central server fails, any other developer has the latest version library locally with a history.

Summary: The main difference lies in the storage of the historical version library. In the centralized system, the historical version only exists in the central server, while in the distributed control system, each local library has the historical record store.


1.2 differences between Git and SVN

Git is not just a version control system, it is also a content management system (CMS), work management system, etc.

Differences between Git and SVN:

  1. Git is distributed, SVN is not: this is the core difference between Git and other non-distributed version control systems (SVN, CVS, etc.).

  2. Git stores content as metadata, whereas SVN stores content as files: all resource control systems hide meta information about files in folders like.svn,.cvs, etc.

  3. Git branches are different from SVN branches: a branch is nothing special on SVN, just another directory in the repository.

  4. Git does not have a global version number, whereas SVN does: this is by far the biggest feature Git lacks compared to SVN.

  5. Git’s content integrity is superior to SVN’s: Git’s content storage uses the SHA-1 hash algorithm. This ensures the integrity of the code content and reduces damage to the repository in the event of disk failures and network problems.


Install Git

Download Git installation package for each platform: git-scm.com/downloads (download according to your system)

2.1. Install on Windows platform

The Windows installation package can be downloaded at gitforWindows.org/

Once installed, you are ready to use the command-line Git tool (which already comes with an SSH client), as well as a graphical Git project management tool.

Go to “Git”->”Git Bash” in the Start menu. This will bring up a Git command window where you can perform Git operations.


2.2. Install on Mac platform

Mac installation package download address: sourceforge.net/projects/gi…

The installation interface is as follows:

For more installation methods, see git Installation in the Rookie tutorial


Git configuration

Git provides a tool called Git Config that is used to configure or read the corresponding workspace variables.

These variables can be stored in three different places:

1. /etc/gitconfig file: a configuration applicable to all users. If you use git config with the –system option, this is the file you read and write to.

2. ~/. Gitconfig file: the configuration file in the user directory is applicable only to the user. If you use git config with the –global option, this is the file you read and write to.

Git /config file (the configuration file in the current project’s Git directory) : this configuration is only valid for the current project.

Each level of configuration overrides the same configuration above, so the configuration in.git/config overrides the variable of the same name in /etc/gitconfig.

The instance

Set user information when submitting code:

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
Copy the code

If you use the –global option, all your projects will default to the user information configured here. To use a different name or email for a particular project, simply remove the –global option and reconfigure it. The new Settings are stored in the.git/config file of the current project.

Viewing Configuration Information

$ git config --list
Copy the code

View the Settings of an environment variable, such as viewing user name information

$ git config user.name
Copy the code

Edit git configuration files:

$git config -e #Copy the code

Or:

$git config -e --global #Copy the code


Create a version library

4.1 initialize a local Git repository

Use the git init command.

Execute commands in the target directory (such as learngit)

$ mkdir learngit
$ cd learngit
$ git init 
Initialized empty Git repository in /Users/michael/learngit/.git/
Copy the code

Add files to Git repository in two steps:

Git add is a command that can be used multiple times to add multiple files. Run git commit -m to complete the task.


The article source

Git tutorial 1: Introducing Git, installing Git, creating a repository – Yang Huiqing’s personal website