Common remote code base sites have

  1. Github (World’s largest code base)
  2. Gitlab (warehouse commonly used by companies, usually deployed by themselves, Chinese-English)
  3. Gitee (Code Cloud, Domestic Code Base, Chinese)

This section describes how to configure github remote repository.

Encryption-free configuration push

  1. Create a Github account.
  2. Execute commands locallySsh-keygen -t rsa -b 4096-cTo generate the SSH key and public key.
  3. Find it in the local user directory.sshDirectory, win10 system default directory isC:\Users\Lansiny\.ssh.
  4. in.sshDirectory, findid_rsa.pubFile, where the public key is recorded.
  5. Click on the user icon in the upper right corner of Github to opensettingsPage, findSSH and GPG keysOptions.
  6. inSSH KeysAdd a public key and paste itid_rsa.pubIf not filled inTitle, will automatically fill in the global mailbox.
  7. Click on theAdd SSH keyThe configuration is complete.

cloning

Git clone < remote location > < local directory >

Git clone < remote address > will download to the current directory if you do not specify the local directory parameters.

Once the clone is complete, Git will automatically set up a remote repository configuration named Origin for the repository you just cloned. The local master branch is automatically set to track the master branch of the cloned remote repository, or the default branch of any other name.

Remote warehouse configuration

If the repository is initialized locally first, you need to specify the remote repository path to push and pull.

The local repository initialized with Git init does not have a remote repository path, which needs to be added manually.

Git remote add < repository name > < repository path >, specify a remote repository alias, and configure the path.

Git remote -v, you can use this command to view all remote repositories that have been configured or cloned.

Git remote show, or git remote, lists all remote repository names.

Git remote show < remote repository name > to view details about a remote repository.

Git remote rm < name of remote repository to be deleted > deletes the specified remote repository configuration. Rm can also be written as remove.

Git remote rename < repository name > < new repository name > changes the name of a locally configured remote repository without affecting the remote repository.

After changing the name of the remote repository, the name of the remote trace branch is also changed. After deleting the remote repository, the remote trace branch and configuration information are also deleted.

Branch management

A branch cannot be created immediately when the repository is initialized. A branch takes a commit record as a node and must be committed at least once to create a branch.

Collaborative development relies heavily on Git’s branching capabilities.

Git branch < branch name > creates a new branch.

Git switch < branch name > to switch to the specified branch.

Git checkout -b < branch name > creates a new branch and switches to the new branch, which is a shorthand for the two commands above.

Git branch, view all branches, asterisks are currently distributed.

Git branch -d < branch name >

Git branch -d < name of the branch to drop > forcibly deletes the local branch, regardless of whether it has been merged.

push

Git push < remote repository name > < local branch name to push > pushes the local branch to the remote repository.

Note that when git is creating a new repository, you can select some initial configurations, such as readme. md,.gitignore and LICENSE, in the page. If there are initial configurations, you need to pull them once before pushing them. If the warehouse is empty, you can push it directly.

The first push may raise an error telling you that no upstream branch (trace branch) was specified.

Git push –set-upstream < remote repository name > < local branch name to push >

Git push. After the last command, you can quickly push the current branch to the upstream branch.

If the local branch has a different name than the remote branch, git push < remote repository name > < local branch name >:< remote branch name > is used to push the local dev branch to the remote master branch.

Git push < remote repository name > –delete < branch name to delete > to delete the specified branch of the specified remote repository.

Get and pull

If it is collaborative development, there will often be two people clone the warehouse at the same time, after each change, and then submit it at different times, the proposal fails, at this time, you need to synchronize the remote warehouse and the local warehouse, and then submit. That is, if there is a new push on the remote side, merge conflicts need to be handled, and if there is no new push, merge conflicts need not be pulled and handled. The following two commands are used to synchronize the remote warehouse.

Git fetch < remote repository name > You can retrieve data from a remote repository that you don’t have, and when you’re done, you’ll have references to all branches in that remote repository that you can merge or view at any time. After cloning, you can run this command to capture all the newly pushed work of the remote warehouse after cloning, or all the newly pushed work since the last capture. This command does not automatically merge, but simply downloads the data from the remote repository.

Git pull < remote repository name > < remote branch name to pull > Pull the Master branch of origin repository and merge it with the local branch. If a change occurs in the same place in the same file, a conflict will occur and the merge will not be possible.

Typically, after the clone repository is complete, git fetch is used to fetch the repository information, and after the content changes are complete, Git pull is used to synchronize the contents of the branch, and then Git push.

Branch merging and conflict handling

Git merge < branch name to merge >, you can merge the specified branch into the current branch. If the current branch is committed one or more times ahead of the branch that needs to merge, there is a high probability that conflicts will need to be handled. Because it’s possible to change the same place in the same file at the same time. Git pauses at this point and waits for you to resolve the merge conflict.

You can use the git status command to view files that were not merged because of conflicts.

<<<<<<< HEAD:test. TXT Indicates the conflict contents in the test. TXT file of the current branch.

=======, using this symbol to separate the current branch from the conflicting content of the branch to be merged.

>>>>>>> dev:test. TXT Indicates the conflict content in the test. TXT file of the dev branch.

After handling the conflict, the < < < < < < <, = = = = = = =, and > > > > > > > these tags to delete, and then use the git add < filename > command to mark this file conflict has been solved.

After you exit the merge tool, Git asks if the merge was successful. If you say yes, Git will hold those files temporarily to indicate that the conflicts have been resolved, you can use git status again to check that all conflicts have been resolved.