Use of Gitee

Introduction of gitee

  1. The role of git: multiple people collaboratively edit code.

  2. How can multiple people edit code collaboratively?
    Based on this, several git concepts have emerged:
    1) git warehouse: Principle: On the basis of the local hard disk, the virtualized "git warehouse"
    needs to use the git command to put the files on the hard disk into the git warehouse.
    2) The role of the git warehouse: "push-push" the git warehouse to the remote (such as gitee.com),
    then the git warehouse can be downloaded (pull) + collaborative development by others.

    git operation - initialization + hard disk code synchronization to git warehouse

  3. git init: Initialize the git warehouse
    Principle: Under the execution folder, a .githidden for the creation of the git warehouse

    The principle of git warehouse code storage:
    1) Assume that the newly created text file means that it is a text file created on the hard disk;
    vscode shows that the file name is green; green means that the file has not been placed in the git warehouse

  4. Synchronize the hard disk code with the git warehouse
    1) git add .: put the newly added text files on the hard disk into the "git temporary storage"
    2) git commit -m '描述语句': put the files in the "git temporary storage" into the "git warehouse"

git repository push to remote

  • git remote add origin [email protected]:zilong0322/my-first.git
    Function: link the local warehouse with the remote warehouse (a project only needs to be done once at the very beginning)

  • git push -u origin "master"
    function: push the local warehouse to the remote warehouse.

    VSCODE:
      1)源代码管理工具:若其有 ⭕️数字的话,即表示 硬盘 与 git 仓库 代码不同步
        操作:
           VSCode 提供的,将 `git add .` +  `git commit -m '描述'` 合二为一的操作办法:
       左侧工具栏:`源代码管理`,在「消息」栏内写完,点「提交」,等同于上述,两步操作
    

    Q: What is the use of git add fileName?
    Put the specified file into the git temporary storage, so that the temporary file can be put into the git warehouse through commit.

How does git generate/add public key

Gitee provides a Git service based on the SSH protocol. Before using the SSH protocol to access the warehouse, you need to configure the SSH public key of the account/warehouse.

ssh-keygen -t ed25519 -C “[email protected]

Follow the prompts and press Enter three times to generate the ssh key. Obtain your public key by viewing the contents of the ~/.ssh/id_ed25519.pub file

cat ~/.ssh/id_ed25519.pub

  • SSH public key and private key
    function: to ensure that each push, no need to enter the account number and password
  1. Get the local public key:
    https://blog.csdn.net/shog808/article/details/76563136 under windows

  2. How to generate a public key:
    https://gitee.com/help/articles/4181#article-header0

  3. Q: How to obtain the local public key?
    1) If the machine has never generated a public key, generate the public key first: ssh-keygen
    2) If the machine has a public key:
    1- Command line: cd ~/.ssh directory
    2- cat id_rsa.pub to view the public key

git commit rollback

  1. git rollback
    git reset --hard specifies the commitHash string
    Function: roll back the local commit chain to the position of the specified commitHash string (delete the original commit after that)

  2. git push -f origin master
    pushes the local warehouse to the remote,
    that is, it forces the remote to be consistent with the local.
    Note: This operation is very dangerous, and it is strongly recommended not to use it.

git-branch branch

  • The technical point of git branch:
    git branch: View local, how many branches are there in total
  1. How to create a branch: git checkout -b newBranchName
    Function: Create a new branch newBranchName from the current branch
  2. From the current branch, switch to another existing branch:
    git checkout 已有分支名
  3. How to merge the code of a certain branch into the current branch: git merge 要合并进来的分支
    After the development of the local branch is completed and pushed to the remote, after the PR is successful.
    Locally switch back to the master branch
    from the master git pull origin master
    branch Synchronize the latest code of the master to the local master
    and then cut out a new function development branch based on this: feature/xxx
  4. The process of Pull Request:
    • Submit the local code to the remote:git push origin 分支名
    • On the remote gitee.com, create a new "Pull Request" submission
    • The technical leader conducts Code Review, and after confirming that the code is correct, merge it into the master branch.

Common Branch Naming

feature/xxx   某一个新功能分支
dev/xxx   ≈  feature/xxx
bugfix/xxx  修复bug的分支

git merges other branch codes into its own branch

  1. Now create a local branch that you want to merge (take dev as an example)
git branch dev
  1. switch to dev branch
 git checkout dev
  1. Pull dev branch code (two ways)
git pull origin dev
git branch --set-upstream-to=origin/dev 
git push
  1. Switch to your own branch
git checkout xxx
  1. Merge your branch
 git merge dev
  1. submit code
git push -u origin xxx

How does git merge the branch code into the master main branch

  1. First switch to the branch
git checkout 分支
  1. Use git pull to pull the branch code down
git pull
  1. switch to master branch
git checkout master
  1. Merge the code of the branch to the main branch
git merge 分支
  1. git push is pushed up and ok is completed, and now the code of your own branch is merged into the main branch
git push origin 分支

Summarize:
insert image description here

Guess you like

Origin blog.csdn.net/lj1641719803hh/article/details/128328174