Using Git


Get to know Git

What is git?

Git is an open source distributed version control system, which can deal with the version management of projects from very small to very large effectively and rapidly.

What is version control?

Version control is a kind of software engineering technology used to manage the modification history of files, directories or projects in the process of development. It is convenient to view the change history and back up in order to restore the previous version. In short, it is the technology of managing multi person collaborative development project.

Realize cross regional and multi person collaborative development
Track and record the history of documents
Better statistical workload
Parallel development, improve development efficiency
Track and record the whole project software development process
Reduce the burden of developers, save time

The difference between GIT and SVN

Svn is a centralized version control system, Git is a distributed version control system

Centralized version control: all version data are saved on the server, and co developers can update or upload their own modifications synchronously from the server

Using Git

Distributed version control: the client not only extracts the latest version of the file snapshot, but also mirrors the original code warehouse completely. In this way, if any server used for collaborative work fails, it can be recovered with any local warehouse after the failure. This kind of system can specify to interact with several different remote code repositories. In this way, you can work with different working groups on the same project. You can set different collaboration processes according to your needs.

Using Git

Git stores files locally and then pushes them to the server. SVN interacts with the server directly

Git can work without network connection, SVN must work with network connection

Git content is stored as metadata, SVN is stored as file

Git only cares about whether the whole file data changes, while SVN only cares about the specific differences of the file content.
Git creates a. Git directory under the root path for each project. It is the place where git stores metadata and object databases. This directory is very important. Every time the image warehouse is cloned, the data in this directory is actually copied.

Git has no global version number, SVN has a global version number

Git can open unlimited branches in its own local version library. The SVN branch is a complete directory with complete actual files

work area

The directory you can see on your computer.

Temporary storage area

Store uncommitted changes in the workspace.

There is a hidden directory. Git in the workspace. This is not the workspace, but the version Library of GIT; There are many things in Git’s version library, the most important of which is the temporary storage area called stage, the first branch master that git automatically creates for us, and a pointer to the master called head. Git puts all the changes to be submitted to the temporary storage area, and then submits all the changes to the temporary storage area at one time.

Git configuration and remote warehouse connection

Configure local email and user in Git client,

Using Git

Create local SSH

Using Git

Adding SSH key to GitHub

Using Git

Configure SSH to GitHub and use the command: SSH – t [email protected]

Using Git

Common git operation instructions

git clone

Copy git warehouse to local

Using Git

git log

View all submitted project version information

Git reflog: you can view all operation records of all branches (including deleted commit records and reset operations)

git status

View file status

git add

Submit the changed documents to the temporary storage area

Git add. Commit all changes to the cache, excluding deleted files
Git add - a submit all changes

git commit

Submit the staging file to the local version library

Git commit - M 'MSG' Submit add remarks, SMG is remarks information
If there are too many comments, you can make comments in the following forms:
git commit -m '

git push

Commit local repository branch to remote branch

Git push origin master pushes the local branch to the remote branch with tracking relationship. If the remote branch does not exist, it will be created

git pull

Get remote branch update content

Git pull origin test1 remote branch test1 merges with current branch
Git pull origin test1: the test1 branch of the master origin host is merged with the local master branch

git branch

View branches

Git branch view local branch
Git branch - R view remote branches
Git branch - a view all branches
Git branch test1 creates a local branch named test1
Git branch - D test1 delete local branch test1

git checkout

Switch branches

Git checkout - b create and switch branches

git fetch

Get remote branch to local

Git fetch -- all get all remote branches

git merge

Merge branches

Development steps of using git (personal experience)

Use general workflow:

  1. Git pull updates local files; If the remote changes, you need to synchronize the remote content
  2. After local modification, you can view the modified file through git status
  3. Use git add to add the modified file to the buffer temporarily
  4. Git commit adds the contents of the staging area to the current workspace
  5. Git push submits the local modification to the remote git server