Introduction to git use

Keywords: git github

Gitee Project Management

Introduction to git

Important Master of Basic Use of git

Operational gitee mastery of remote warehouses

Mastering with git in IDE(vscode webstrom idea)

Introduction to git:

Git is currently the most advanced distributed version control system in the world (none), open source, free of charge.

Role: Can quickly manage projects (a collection of files)

Distributed:

Version Control System:

Other common version control tools:

svn(subversion) centralized

CVS

Effect:

Main role:

Can quickly manage project (a collection of files) versioning

Collaborative Modification

Data backup

Permission Control

History Management

Branch Management

Download:

https://git-scm.com/

Install foolish installation.

Local warehouse:

Learn the management of local warehouses first. You can create many local warehouses on your own computer.

Remote warehouse:

Re-learn management of remote warehouses
 Within the LAN:
    gitlab The server
 In an external network environment:
    github  
    Code cloud ( gitee)
    coding

The author of git is the author of linux:

linux is an operating system. Most commands in linux can be used in git bash.

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop

~The Home Directory Desktop is the desktop

Windows is also a multi-user OS where each user has a directory called Home Directory

Common commands for linux:

touch xxx.txt Create a file name that is xxx.txt
mkdir  aaa  Create a folder 
clear  Clear screen
ls  Lists which files or directories in the current directory folder do not contain hidden files or directories
ls -all Lists which files or directories in the current directory folder contain hidden files or directories
 The up and down arrows on the keyboard call out commands you've typed before
rm File name Delete a file

Detect git version:

git --version

1. Basic use of git:

1) Set up user name and mailbox (first time)

Role: Tell git Who are you

git config --global [user.name](http://user.name) yuanfang

git config --global user.email [2667074093@qq.com](mailto:2667074093@qq.com)

2) Create a folder, initialize it into a local warehouse

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop

$ mkdir wyy-music

Get into wyy-music  

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop

$ cd wyy-music/

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/wyy-music

Initialize this folder into a cost local warehouse

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/wyy-music

$ git init

Initialized empty Git repository in C:/Users/Administrator/Desktop/wyy-music/.git/

3) Management of local warehouses

Under this folder, it is divided into three areas:

  Workspace We all create files or folders in the workspace

  Cache (Temporary Zone) If you say you created a file or folder, you want to git Manage, you need to throw the code of the workspace into the staging area

    Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/wyy-music (master)

    $ git add readme.txt

  The above command: Indicates that the workspace's readme.txt Drop in Cache    Version cannot be formed at this time

  Historic Area: A version can only be formed by throwing the cached files into the Historic Area  

    Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/wyy-music (master)

    $ git commit -m "Establish readme.txt Description File"

    -m Comment on this version later Each company has its own specifications

4) View version:

git log    Each version has a unique ID  

// master represents the main branch  

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/wyy-music (master)

$ git log

commit a027a36a008ed8be834128b24d6cffc5eb02742e (HEAD -> master)  // HEAD is pointer

Author: yuanfang [2667074093@qq.com](mailto:2667074093@qq.com)

Date:   Wed Sep 22 10:16:36 2021 +0800

  Establish readme.txt Description File

2. The process of creating a new file or folder later:

1) View status using git status

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/wyy-music (master)

$ git status

On branch master

Untracked files:

(use "git add ..." to include in what will be committed)

index.js(Red, indicating that the code for the workspace was not thrown into the cache)

nothing added to commit but untracked files present (use "git add" to track)

2) git add * * means that all files or folders in the workspace (if they are empty, Git is not managed) are thrown into the cache

git add .    with    git add *

3) git diff file name compares working files with cached files

Add code in the workspace: var one = "one111";

The comparison is as follows:

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/wyy-music (master)

$ git diff index.js

diff --git a/index.js b/index.js

index c388cd5..2d26b36 100644

--- a/index.js

+++ b/index.js

@@ -1 +1 @@

-var one = "one";

\ No newline at end of file

+var one = "one111";

\ No newline at end of file

3. Viewing the version emphasizes:

Default:

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/wyy-music (master)

$ git log

commit 0ac26121e8b977751e92e4730633dba27b26abad (HEAD -> master)

Author: yuanfang [2667074093@qq.com](mailto:2667074093@qq.com)

Date:   Wed Sep 22 10:28:38 2021 +0800

  Create project entry file

commit a027a36a008ed8be834128b24d6cffc5eb02742e

Author: yuanfang [2667074093@qq.com](mailto:2667074093@qq.com)

Date:   Wed Sep 22 10:16:36 2021 +0800

  Establish readme.txt Description File

Simplified display:

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/wyy-music (master)

$ git log --pretty=oneline

0ac26121e8b977751e92e4730633dba27b26abad (HEAD -> master) Create project entry file

a027a36a008ed8be834128b24d6cffc5eb02742e Establish readme.txt Description File

View the short version:

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/wyy-music (master)

$ git reflog

0ac2612 (HEAD -> master) HEAD@{0}: commit: Create project entry file

a027a36 HEAD@{1}: commit (initial): Establish readme.txt Description File

git reflog You can show that all versions contain versions that you have fallback on.

4. Forward and backward versions:

Git reset--Hard version ID goes back to any version and can go back with git reflog

Git reset--hard HEAD^ HEAD^ means to go back to the previous version HEAD^^ means to go back to the previous version

5. Removing documents related to:

If a file is deleted by us:

1)Deleted, not submitted ( commit)

  Recover files:

    A)git reset --hard  Edition ID  (Probable problems) 

    B)git checkout -- App.js(Deleted file name)   

2)Deleted, submitted (version formed)

  Recover files:  

    git reset --hard  Edition ID 

If the file does not form a version, you delete it and it cannot be found.

6. Branch management:

By default, our operations are performed on the master branch. The master is also called the master branch.

Real development, different companies have their own branch management specifications.

They are divided into different branches according to their functions.

They are divided into different branches based on their members.

Create branch:

git branch Branch name    Created on an existing version.

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/wyy-music (master)

$ git branch b1

Once created, it does not automatically switch to b1 branch  

View branch:

git branch -v  

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/wyy-music (master)

$ git branch -v

  b1     e407765 Yes axios For secondary packaging at this time b1 There are also on branches master Branch above

- master e407765 Yes axios Conduct secondary packaging current processing master branch

Switch branch:

git checkout b1  

Merge Branches:

Cut first to the main branch that accepts the merge    git checkout master 

git merge  b1  

Delete branch:

git branch -d b1 

7. Remote warehouse management:

Using gitee as a remote warehouse requires you to register an account.

8. Create a remote warehouse:

Once created, each remote warehouse has an address:

There are two categories:

  1)[https://gitee.com/tubie/wyy-music.git](https://gitee.com/tubie/wyy-music.git) The first time you walk https, you may be prompted for a username and password

  2)git@gitee.com:tubie/wyy-music.git

Use addresses starting with https first

Clone remote warehouse to local:

git clone [https://gitee.com/tubie/wyy-music.git](https://gitee.com/tubie/wyy-music.git)

By default, your cloned warehouse is associated with a remote warehouse.

Recommend version of local warehouse to remote warehouse:

  git add .

  git commit -m "Set your own content comments"

  git push Address of remote warehouse ([https://gitee.com/tubie/wyy-music.git](https://gitee.com/tubie/wyy-music.git))

  When the code is written later, the local warehouse is managed first, then the remote warehouse is managed. 

9. Above, each time a version of a local warehouse is thrown into a remote warehouse, it is the address of the git push remote warehouse.

Alias the address of the remote warehouse:

Git remote-v See what aliases the remote warehouse has

Administrator@MS-SXACBDGCBVLV MINGW64 /e/wyy-music (master)

$ git remote -v

origin https://gitee.com/tubie/wyy-music.git (fetch)

origin https://gitee.com/tubie/wyy-music.git (push)

There is a default alias called origin.

That is, you can push like this: git push origin master

Alias the remote warehouse again:

git remote add music [https://gitee.com/tubie/wyy-music.git](https://gitee.com/tubie/wyy-music.git)

Once aliased, use when pushing data  $ git push music(alias) master

Administrator@MS-SXACBDGCBVLV MINGW64 /e/wyy-music (master)

$ git push music master

Delete Alias:

git remote remove music 

10. Mapping a remote warehouse to a local warehouse (https mode)

You may need to sign in.

Create a remote warehouse independently, called first, and create a local warehouse independently, called one. By default, there is no relationship between the two.

You can see if a local warehouse has an alias for a remote warehouse through git remote-v.

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/one (master)

$ git remote -v

The local warehouse now needs to contact the remote warehouse:

git remote add origin https://gitee.com/tubie/first.git

Save local version to staging area first

git add .

git commit -m "xxxx"

Throw version of local warehouse into remote warehouse

git push origin master

11. Remote warehouse mapped to local warehouse (SSH mode)

No login required

The configuration is as follows:

Open one dos window(win+R+cmd)´╝îEnter the following:

C:\Users\Administrator>ssh-keygen -t rsa -C "[2667074093@qq.com](mailto:2667074093@qq.com)"    Direct Quadruple Enter  

Generated in Home Directory.ssh Directory, which has two files, a private key and a public key, copy the public key.

![](https://secure.wostatic.cn/static/azJomV1pyuSVUYkeWWsuMU/V4`[@ZH~MD]YULN2DIUQL9U.png)

Open the code cloud, copy To the yard cloud(stay Gitee On the web page, find the settings under the avatar and click to find SSH Public key, set it up). 

These configurations are complete. Later, you can use this address: git@gitee.com:tubie/first.git

When pushing back:

Administrator@MS-SXACBDGCBVLV MINGW64 ~/Desktop/one (master)

$ git remote add origin [git@gitee.com](mailto:git@gitee.com):tubie/first.git

git push origin master

12. In the current situation, the remote warehouse does not move and the local warehouse submits the version to the remote warehouse.

Is there a case where the remote warehouse version is ahead of our local warehouse?

A: Yes

If the version of your local warehouse is inconsistent with that of the remote warehouse, the submission of the version created by the local warehouse to the remote warehouse is unsuccessful.

At this point, you need to use git pull to pull the version you don't have from the remote repository.

That is, before you push a new version, go to pull.

git pull origin master

(If you pull a file from a remote repository, it may go into file editing mode, so you need a lower level operation)

: wq quits vi editing

Recommend version of local warehouse to remote warehouse:

git add .

Git commit-m "Set your own content comments"

Address of GIT push remote warehouse or git push origin master

When the code is written later, the local warehouse is managed first, then the remote warehouse is managed.

Posted by NTM on Wed, 20 Oct 2021 09:53:07 -0700