The basic operation of git remote warehouse and solving the problem of remote merge conflict

Before sharing how to establish a connection between the local warehouse and the remote warehouse, this time I will share how to clone, pull and other operations from the remote reference

If there is already a remote warehouse, we can directly clone to the local.
        Command: git clone < repository path > [ local directory ]
        The local directory can be omitted, and a directory will be automatically generated. The name of the directory is the name of the warehouse
Need to start git bash from desktop right click
The warehouse path is the SSH address
In this way, you can see a folder cloned from the remote warehouse on the desktop
The remote branch is the same as the local branch. We can perform the merge operation, but we need to download all the updates in the remote warehouse to the local before performing the operation.
        Fetch command: git fetch [remote name] [branch name]
        The grab command is to grab all the updates in the warehouse locally without merging
        If no remote name and branch name are specified, all branches are fetched.
        Pull command: git pull [remote name] [branch name]
        The pull command is to pull the modification of the remote warehouse to the local and automatically merge it, which is equivalent to fetch+merge
        If no remote name and branch name are specified, fetch all and update the current branch.

 

Create a text locally and submit it to the local repository.

Submit the local warehouse to the remote warehouse

But there is no content of this modification on other warehouses, so you need to pull the remote warehouse

 Here is a demonstration of using the git fetch command

We can see that new content has been fetched, but at this time the local branch and the branch of the remote warehouse are not under the same modification, and a merge is required at this time.

This requires entering two commands, which is a bit troublesome, so there is a git pull command on the git side that can grab and merge, called pull 

 

        Create a file04.txt file in other warehouse programs, and then execute git pull to see that not only the modified content of the remote warehouse is obtained, but also the local branch and the branch of the remote warehouse are merged. 

        Next, let's introduce the problem of merge conflicts in remote warehouses.

        During a period of time, users A and B modify the same file, and modify the code at the same line position, and a merge conflict will occur at this time. After user A modifies the code locally, it is first pushed to the remote warehouse. At this time, user B revises the code locally. After submitting it to the local warehouse, it also needs to be pushed to the remote warehouse. At this time, user B is later than user A , so the remote needs to be pulled first. The submission of the warehouse can only be pushed to the remote branch . At this time, the issue of merge conflict will be sent. Demonstrate it here.

 Modify the file01.txt file on a local warehouse

 Submit to remote repository

Modify the same file and the same line in another local warehouse

Submit to the local warehouse, and pull from the remote warehouse at this time.  

At this time, the problem of merge conflict will appear.

Viewing files is consistent with the problem of branch merge conflicts, so the solutions are also consistent. Modify the content of the file and resubmit

 

Resubmit to the remote warehouse

 

Just re-pull on another warehouse. 

Guess you like

Origin blog.csdn.net/qq_45526401/article/details/127562773