Git study notes arrangement


Bad writing is better than a good memory. Writing down is the best way to resist forgetting


  1. Note outline, mind map as follows:

  1. The directory structure
  • Chapter 1 – Introduction to Git
  • Chapter 2 -Git Installation
  • Chapter 3 -Git Common commands
  • Chapter 4 -Git Branch ⭐(Important)
  • Chapter 5 — Git teamwork
  • Chapter 6 -GitHub Operations
  • Chapter 7 -IDEA integration with Git
  • Chapter 8 -IDEA integration with GitHub
  • Chapter 9 – Domestic Code Hosting Center – Code Cloud Gitee
  • Chapter 10 – Creating a code hosting platform -GitLab

Chapter 1 – Introduction to Git

Git is a free, open source distributed version control system that can handle projects from small to large quickly and efficiently.

Git is easy to learn, small footprint, and extremely fast. It features inexpensive local libraries, convenient staging areas, and multiple workflow branches.

It outperforms version control tools like Subversion(SVN), CVS, Perforce, and ClearCase.

It-scm.com Git it-scm.com

Based on the latest version of Git-2.31.1


1. What is version control

Version control is a system that records changes to the contents of a document so that future revisions to a particular version can be reviewed.

The most important thing about version control is that it can record the history of file changes, so that users can view the historical version and easily switch versions.

Let me give you an example of the confusion I experienced when I changed hexo blog 😂

2. Why version control

My personal superficial understanding is convenient to manage the file, the most important thing is to do the project needs the team development, the code is not convenient to manage, need to transition from individual to team development!! The idea of version control is there, but there are no administrative tools. So version control tools are a good solution to this problem.


3. Version control tools

Version control tools are divided into centralized version control tools and distributed version control tools

3.1 Centralized version control tool

As far as I know and refer to, the centralized version control tool is SVN,CVS, SVN(Subversion), VSS…

  • Overview: There needs to be a single, centrally managed server to which all developers working together connect through clients. Retrieve the latest file or submit an update. This is standard practice for version control systems!

    advantages disadvantages
    Everyone can see to some extent what others on the project are doing. A single point of failure on a central server
    Administrators can also easily control the rights of each developer and manage a centralized version control system. Server Breakdown
    It’s much easier than maintaining local databases on individual clients. No one could submit updates or work together during the outage.

3.2 Distributed version control tools

Git, Mercurial, Bazaar, Darcs…

Git distributed version control tool, the client does not take a snapshot of the latest version of the file, but a complete mirror of the code repository (local library).

When a co-working file fails, it can be recovered from the local repository of another client.

Each file extraction for each client is, in effect, a complete backup of the entire file repository.

Distributed version control systems address the drawbacks of centralized version control systems:

  1. It can also be developed in the case of a single point of failure of the server (because version control is done locally)
  2. Each client also saves the entire project (including history, which is more secure)

4.Git development history

4.1 introduction

Git was born in a time of great strife and innovation. From the same father of Linux, Linus Benatict Torvalds

The Linux kernel open source project has a large number of participants. The vast majority of Linux kernel maintenance was spent on the tedious task of submitting patches and keeping archives (1991-2002). By 2002, the entire project began implementing a proprietary distributed version control system, BitKeeper, to manage and maintain the code.

It took Lin two weeks to develop Git, big guy is strong!!

5. How Git works

6.6 Git and Code Hosting Center (Remote Repository)

  • ➢ LAN

    1. ✓ GitLab
  • ➢ Internet

    1. ✓ ✓ GitHub (Internet)
    2. ✓ Gitee code cloud (domestic websites)

    The introduction of Git is here, probably have a understanding ~🙂


Chapter 2 -Git Installation

It-scm.com Download Git on it-scm.com

Installation diagram with detailed explanation:

Git --versionCopy the code

Installation complete!! Really not, no brainless next step can be installed


Chapter 3 -Git Common commands

Git Account Settings

# git config --global user. Name "ck_cheng" 2.# git config --global user  config --global user.email [email protected]Copy the code

Initialize the local library

Git init #Copy the code

View local library status

git status
Copy the code

Add to staging area

Git add. Add all the filesCopy the code

Commit to a local library

Git commit -m "Log info" file nameCopy the code

Viewing Historical Records

Git reflog Check version information git log Check version informationCopy the code

Version of the shuttle

Git reset -- Hard version numberCopy the code

Git switch version, the bottom is actually moving the HEAD pointer

Chapter 4 -Git Branch ⭐(Important)

1. The concept

During version control, multiple tasks are pushed simultaneously, creating separate branches for each task.

The separation from the development mainline does not affect the operation of the mainline branch when you develop your own branch.

2. Branch operations

The command role
Git branch Specifies the branch name Create a branch
git branch -v See the branch
Git Checkout branch name Switch branch
Git merge branch name Merges the specified branch to the current branch

3. Code conflicts

2. The state is complex

The reason for the conflict: When merging branches, the two branches have two completely different sets of changes in the same place in the same file. Git can’t decide for us which one to use. New code content must be artificially determined.

4. Conflict resolution

Edit conflicting files, remove special symbols, and decide what to use

Special symbols: < < < < < < < the HEAD of the current branch code = = = = merger over > > > > > > > branch name

Git commit


Chapter 5 — Git teamwork

1. Work within a team

2. Work across teams


Chapter 6 -GitHub Operations

1. Remote library operations

The command role
git remote -v View all current remote address aliases
Git remote add Alias remote address names
Git push alias branch Push content from a local branch to a remote repository
Git pull Remote library address Alias Remote branch name Pull down the latest content of the remote repository for the branch and merge it directly with the current local branch
Git Clone Remote address Clone the contents of the remote repository locally

2. Invite to join the team

Add personnel

3.SSH password-free login

Go to the current user's home directory CD. 2. Delete the. SSH directory rm -rvf.ssh 3. SSH key directory [note: -c is an uppercase C] ssh-keygen -t rsa -c [email protected] Press 4. SSH ll -a 5. Cat id_rsa.pub Copy the id_rsa.pub file, log in to GitHub, and click User profile picture →Settings→SSH and GPG keysCopy the code

Chapter 7 -IDEA integration with Git

1. Configure Git to ignore files

Role: Ignore the differences between tools that can mask IDE.

Create an ignore rule file named xxxx.ignore.

Suggestions are also placed in the home directory

2. Git. ignore file template:

# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see 
http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.classpath
.project
.settings
target
.idea
*.iml
Copy the code

3. Reference the ignore configuration file in the.gitconfig file (this file is in the Windows home directory)

[user] name = ck_cheng email = [email protected] [core] excludesfile = C:/Users/Daly/git.ignore Use "forward slash (/)" instead of "backslash (\)"Copy the code

4. Locate the Git program

The IDEA to open the File – > Settings

Branch operations in idea


Chapter 8 -IDEA integration with GitHub

1. Set a GitHub account

Chapter 9 – Domestic Code Hosting Center – Code Cloud Gitee

IDEA integrated code cloud

IDEA install code cloud plug-in IDEA does not have code cloud plug-in by default, our first step is to install Gitee plug-in.

Similar to Github


Chapter 10 – Creating a code hosting platform -GitLab

1. Introduction

GitLab is an MIT licensed web-based Git repository management tool developed by GitLabInc., with wiki and issue tracking features. Using Git as a code management tool, and built on the basis of web services.

GitLab was developed by Ukrainian programmers DmitriyZaporozhets and ValerySizov and is written in Ruby. Later, some parts were rewritten in Go. As of May 2018, the company has approximately 290 team members and more than 2,000 open source contributors.

GitLab is supported by IBM, Sony, JulichResearchCenter, NASA, Alibaba, Invincea, O ‘reilly media, leibniz-rechenzentrum (LRZ), CERN, Used by organizations like SpaceX.

2. GitLab official website address

Official website: about.gitlab.com/

Installation instructions: about.gitlab.com/installatio…

3. Prepare the server

The OS must be CentOS7 or later, and the memory must be 4 gb and the disk must be 50 gb. Disable the firewall and configure the host name and IP address to ensure that the server can access the Internet.

4. Prepare the installation package

When installing Gitlab-CE online, you need to download hundreds of MB of installation files, which is very time-consuming. Therefore, it is best to download the required RPM packages to the local PC in advance and use the offline RPM mode to install gitlab-CE.

Download address: packages.gitlab.com/gitlab/gitl…

5. Write an installation script

Sh sudo RPM -ivh /opt/module/gitlab-ce-13.10.2-ce.0.el7.x86_64. RPM sudo yum install -y curl policycoreutils-python openssh-server cronie sudo lokkit -s http -s ssh sudo yum install -y postfix sudo service postfix  start sudo chkconfig postfix on curl https://packages.gitlab.com/install/repositories/gitlab/gitlabce/script.rpm.sh | sudo bash sudo EXTERNAL_URL="http://gitlab.example.com" yum -y install gitlabceCopy the code

Add execution permission to a script

chmod +x gitlab-install.sh

 ll
 
#Then execute the script to start installing Gitlab-CE. Make sure that the server has Internet access.
 ./gitlab-install.sh 
 
 
Copy the code

6. Initialize the GitLab service

Run the following command to initialize the GitLab service. The process takes a few minutes.

 gitlab-ctl reconfigure
Copy the code

7. Start GitLab service

Run the following command to start the GitLab service. To stop the service, run the gitlab-ctl stop command

 gitlab-ctl start

Copy the code

8. The idea of integrated Gitlab