Git related instructions and code pulling

Common git operations

Time: October 30, 2023 08:50:21

Prefix: git configuration

  1. First run Git. When running Git for the first time, you need to set user information.

  2. Configure global users

    1. Configure the global user – that is, the user name you submitted in git ( is used to identify the user – no other meaning)

    2. #Set the submitted user
      git config --global user.name "XXX"
      #Set the submission email
      git config --global user.email "[email protected]"
      
    3. Note: This is not the user and email address of the git code warehouse, it is only used for development identification.

  3. View current global configuration

    1. git config --global --list
      
  4. Configure ssh (optional)

    1. What is the use of git setting ssh key?

    2. One of the main functions of git setting ssh key is to achieve passwordless login. By generating a public key and a private key, the public key can be added to the git server, thereby eliminating the need to enter a password every time a git operation is performed. This can greatly improve operational efficiency and reduce the tedious password input process.
      For example, it is often used during automated deployment.
      
    3. How to configure?

      1. First generate the SSH public key, using gitee as an example

        1. First enter the git bash console

        2. # Check whether a secret key has been generated
          cd ~/.ssh
          # If the following appears -- No such file or directory, it means that the secret key has not been generated.
          bash: cd: /c/Users/19839/.ssh: No such file or directory
          
          
        3. # Create ssh public key
          ssh-keygen -t rsa -C "[email protected]"
          
        4. image-20231101150616597

        5. Just enter three times in a row

        6. # View the public key content
          cat ~/.ssh/id_rsa.pub
          
      2. Add public key in gitee

        1. image-20231101150347359
  5. 1

1. Details of basic git commands

  1. Basic command details of git

  2. Pull code repository

    1. # Pull remote warehouse
      git cloneXXX.git
      # View branches
      git branch -a
      
    2. Note that if ssh is added above, you can use the ssh download method

      1. image-20231101151012771
      2. 1
    3. 1

  3. Tips for uploading git code

    1. Create a code branch in the remote git repository and initialize it

    2. git clone xx Create a directory locally and pull the remote repository

    3. Copy the code to the current directory

    4. Upload the code to the remote warehouse

      1. Use idea to open the directory, and commint + push

      2. Use git bash

        1. # Pull code repository
          git clonexxx.git
          #Add the copied files, all files in the current directory, and transfer them to the temporary storage area
          git add .
          # Add explanation
          git commit -m "<message>"
          # Show remote warehouse
          git remote
          -- origin
          # Push to remote warehouse
          git push origin master
          
        2. If it is the first upload, you will be asked to enter your account and password. I have added ssh here and there is no need for user verification.

          1. image-20231101152054015
        3. Go to the remote warehouse and check it. There are files to be uploaded now

          1. image-20231101152230916
        4. 1

2. How to use git in idea

  1. Basic operations

    1. Directly use idea to pull the remote warehouse code

      1. image-20231031140504260

      2. image-20231031140636849

    2. ideaVisual git common instructions

      1. image-20231031140846166
      2. Pull code = code update, update the latest code of the current branch
      3. Submit to local library (commit)
        1. Every time there is a small functional change, you can commit first, and then add comments to explain it.
      4. Push to remote library (push)
        1. Submit multiple commit to the remote warehouse at the same time
      5. View historical information, you can view the commit information of the branch

3. How to merge merge

For example, merge the dev branch into the master branch

  1. First submit the dev branch commit to the cache, otherwise direct switching will prompt that it has not been submitted, and then push submit it to the remote warehouse

  2. image-20231030102444037

  3. image-20231030103531247

  4. checkout + update

    1. Use checkout to switch branches, and save both branches as the latest update
  5. Switch to the branch you want to merge – at this time we want to push the dev branch to the master branch, then switch to the master branch at this time That’s it

    1. There is a branch switching conflict message because not all branch changes have been submitted, only part of them have just been submitted.
    2. image-20231030104146668
  6. Then directly merge

    1. image-20231030104546905
  7. Finally, master branch push

4. What should I do if a conflict occurs in merge?

If multiple people modify this code during the merge process, merge conflicts will occur.

  1. Many people modified this code during the merge merger process.
  2. image-20231031143422893
  3. You can see on this page that there are three options: either accept your recently modified Accept Yours, or accept other people’s previous Accept Theirs, or merge
  4. In most cases, we neither accept our own nor other people’s, we have toMerge
  5. image-20231031143520103
  6. As you can see in the picture, we have a conflict to be resolved at the moment, and idea is asking who should be retained at this moment
  7. image-20231031143932493
  8. explain
    1. Accept Left: Select this button to fully accept the left side (discard our changes)
    2. Accept Right: Select this button to accept the right side in full screen (retain the changes of the current branch)
    3. In the middle is the style diagram of the final branch
    4. image-20231031144429062
  9. After the conflict resolution is completed, you can merge and there will be a prompt.
    1. image-20231031144524737
  10. image-20231031143637345
  11. This is a conflict that has not been resolved. For example, if there are many conflicts and some of them are not resolved, then apply will pop up a prompt box. At this time, we continue continue

5. Tips

  1. To understand and become familiar with the native git native instructions, you can view the console after visualizing the operation in idea
    1. image-20231030104909154