Using Git remote warehouse to realize multi-person collaborative development

(Creating is not easy, thank you, your support is the biggest motivation for me to move forward, if it is helpful to you after reading it, please leave your footprints)

Directory

the branch

First knowledge branch

Branch – merge and delete

Branching – Merging and Committing

branch-merge conflict

Git common commands

Git remote repository

Git remote warehouse – clone

Collaborative development

Git common commands ?Edit


branch

First knowledge branch

Concept: essentially points to
submit node
variable
the pointer
, the default name is master

Note:
HEAD pointer
Affects the state of the code in the workspace/staging area

Scenario: Development
new demand
/
fix bugs
, to ensure that the mainline code is available at any time, and multi-person collaborative development improves efficiency

Example:

Create a new branch on existing code to complete the content list Business suddenly needs an urgent bug fix – create a separate branch to solve the bug

Requirement: Create content list content branch and generate 3 commit records

Steps:

1. Create a branch command:
git branch branch name

2. Switch branch command:
git checkout branch name

3. The workspace prepares the code and stashes the submission, repeating 3 times

Zhou Xingchen@?□□?□□□ヱ MINGW64 /d/Git learning (master)
$ git branch content

Zhou Xingchen@?□□?□□□ヱ MINGW64 /d/Git learning (master)
$ git checkout content
Switched to branch 'content'
A day01/page/login/index.css

Zhou Xingchen@?□□?□□□ヱ MINGW64 /d/Git learning (content)
$ git branch
* content
  the master

Zhou Xingchen@?□□?□□□ヱ MINGW64 /d/Git learning (content)
$ git add .

Zhou Xingchen@?□□?□□□ヱ MINGW64 /d/Git learning (content)
$ git commit -m '7. Content page - title construction'
[content 83b2566] 7. Content page - title construction
 44 files changed, 1369 insertions( + )
 create mode 100644 day01/page/login/index.css
     
Zhou Xingchen@?□□?□□□ヱ MINGW64 /d/Git learning (content)
$ git log --oneline
83b2566 (HEAD -> content) 7. Content page - title construction
b58777f (master) 1. Login page - tab part preparation

Branch-merge and delete

Requirement: Merge login-bug back into master branch and delete login-bug branch

Steps:

1. Switch back to the branch to be merged into: git checkout master

2. Merge other branches over:
git merge login-bug

3. Delete the merged branch pointer: git branch -d login-bug

After writing the new branch login-bug, first switch back to the branch to be merged

Merge the login-bug branch in the current branch

Finally, delete the original login-bug branch

Branch-merge and commit

Merge Commit: Occurred on
original branch
produced
new commit
After recording, then
to merge
Occurs when going back, automatically uses multiple snapshot records to merge and generate a new commit

Steps:

1. Switch back to the branch you want to merge into:
git checkout master

2. Merge other branches over:
git merge content

3. Delete the merged branch:
git branch -d content

When finally merging back to the main branch, submit the record flow chart:

Note:
The order of commit records is arranged according to the order of generation, not the order of merge

Branch-merge conflict

Requirement 1: Create a new publish branch based on the master, complete the publishing business, then modify the title tag of the html file on the content page, and submit it once

Requirement 2: switch to master, also modify the title tag of the html file of the content page, and submit it once

Conflict: Merge the publish branch into master, resulting in a merge conflict

Concept:
different branches
in, yes
the same file
of
the same part
Modify, Git cannot merge cleanly, resulting in merge conflicts

Resolve:

1. Open VSCode to find the conflict file and resolve it manually

2. Need to submit a record after solving

Avoid: (more communication)

1. Divide different branch development by page

2. Public codes are maintained in a unified folder

3. Node and other software versions are unified, and npm packages are downloaded uniformly

Git common commands

Git remote repository

concept:
Your project hosted on the Internet or other networks
Repository

Role: save the history of the version library, multi-person collaboration

Creation: company’s own server / third-party hosting platform (
Gitee
, GitLab, GitHub…)

Requirements: Create a remote repository and push the local Git repository to save

steps:

1. Register a third-party hosting platform website account

2. Create a new warehouse to get
Remote warehouse Git address

3. Local Git repository
Add to
Remote warehouse origin address

Command: git remote add remote warehouse alias remote warehouse address

For example: git remote add origin https://gitee.com/lidongxu/work.git

4. Local Git repository
to push
Version records to remote warehouse

Command: git push -u remote warehouse alias local and remote branch names

Example: git push -u origin master

Complete writing: git push –set-upstream origin master:master

Git remote warehouse – clone

Clone: Copy a Git repository to the local for use

Command:
git clone remote warehouse address,
For example: git clone https://gitee.com/lidongxu/work.git

Effect: In the folder where the command is run, a work project folder (including the version library and mapped to the temporary storage area and work area) is generated

Note 1: The Git local warehouse has established a link with the remote warehouse

Note 2: The warehouse is publicly cloned at will, and you need to be a member of the warehouse team to push

Multiple people collaborative development

Requirement: Share the new code of Xiaochuan to Xiaozhi

steps:

1. Xiaochuan development code -> workspace -> temporary storage area -> submit -> pull (optional) -> push

2. Xiaozhi -> pull (you can also develop code later -> … -> push)

3. Want to see the latest content synced by others:
git pull origin master
Equivalent to

git fetch origin master:master (get remote branch records to local, not merged)

git merge origin/master (merge remote branch records into the branch)

Common Git commands