Creation, cloning, pushing and pulling of Git remote warehouse


insert image description here

1 Introduction

In the previous article, I explained some basic concepts and commonly used commands of Git. It's time to do a big thing - realize multi-person assistance development!

  • Environment: Centos7 cloud server

  • Code hosting platform: Gitee

Gitee is a domestic Git-based code hosting platform, similar to GitHub. It provides source code hosting, version control, project management, collaborative development, and more.

Gitee official website: https://gitee.com/

insert image description here

2. Creation of remote warehouse

After first logging in to Gitee, move the mouse to next to the avatar +, and click to create a new warehouse

insert image description here

Go to the Create Warehouse page

insert image description here

Entering the name of the warehouse will automatically generate the path. If you are not satisfied with the generated path, you can change it manually. You can give a simple description of the warehouse

Whether the warehouse is open source, private, open source within the enterprise cannot be changed when it is just created, it can only be private

insert image description here

.gitignoreis a configuration file that specifies Git to ignore specific files or folders. You can tell Git which files should not be brought into version control by listing the names, patterns, or wildcards of the files or folders to ignore in the file.

For the initialization of the warehouse, you can choose according to your needs.
insert image description here
Let’s talk about the template here:

  • Readme file: is a common document used to introduce the project to project contributors and users. It usually exists in the format of README.md, written using Markdown syntax. Provide project overview, usage instructions, installation guide, contribution guide, sample code and other information so that others can quickly understand and use your project.
  • lssue template file: Issue template files usually exist in .md format, written using Markdown syntax, and contain some predefined fields and guidance information. When creating an Issue, you can fill in the corresponding information according to the field requirements in the template, such as problem description, reproduction steps, expected behavior, actual behavior, etc. (will be introduced later).
  • Pull Request template file: PR template files usually exist in .md format, written in Markdown syntax, and contain some predefined fields and guidance information. When initiating a PR, you can fill in the corresponding information according to the field requirements in the template, such as PR description, modification content, test steps, related issues, etc.

The branch model can be selected according to the requirements.

insert image description here

(I did not initialize, I selected all when setting the template, and selected a single branch)

Click Create to complete the creation

insert image description here

You can see that the README file is generated to explain the description of the project

and a .giteedirectory
insert image description here

The .gitee directory contains lssue files and Pull Request files

Select lssues above to create lssue

insert image description here

The text here comes from the lssue.md file under .gitee, and a series of information can be set on the right.

insert image description here

The lssue file is a way for the person who finds the bug to communicate with the warehouse manager.

insert image description here

The PR file is actually a merge application form. Developers will not develop under the master branch. If the developer wants to submit the development directly to the master branch, he needs to write a merge application form, which requires the approval of the administrator before merging

3. Cloning of remote warehouse

There are four types of cloning remote warehouses to the local:

insert image description here

This article will introduce two methods: 1. HTTPS 2. SSH

Note: Set the warehouse as open source before cloning

3.1 Cloning using HTTPS

Copy the address under HTTPS

Use the command:

git clone [HTTPS网址]

insert image description here

Enter the cloned local warehouse to view

insert image description here
Add two commands:

# 查看远程仓库的名字(默认是origin)
git remote 
# 查看对远程仓库的权限
git remote -v

3.2 Cloning using SSH

Configure the SSH public key, move the mouse to the avatar -> select Settings -> find the SSH public key in the security settings

insert image description here

.sshThen check if there is a directory in our server main directory

insert image description here

If so, check to see if there are any id_rsa(私钥)and id_rsa.pub(公钥)these two files in this directory, if not, you need to create themSSH KEY

Execute the following command:

ssh-keygen -t rsa -C "邮箱" 
# 邮箱要与Gitee上的保持一致

Execute the command, if you need to fill in something, just press Enter, and the following interface will appear to indicate that the configuration is successful

insert image description here

View the file at this time , and these two files .sshwill appearid_rsa(私钥)id_rsa.pub(公钥)

insert image description here

Use catthe command to view id_rsa.pub(公钥)this file, and then copy the string of information that appears.

insert image description here

Paste it into Gitee and confirm it.

insert image description here

Copy the SSH address of the repository:

insert image description here

Then execute git clonethe command

insert image description here

4. Push from remote warehouse

After cloning to the local warehouse, configure the local warehouseuser.name 和 user.email

The command is as follows:

git config [user.name/user.email] []

The username and email address here should also be consistent with those on Gitee

Git's workflow is usually as follows:

  1. Modify (add, modify, delete) files in the workspace.
  2. Add the modified file to the staging area, use git addthe command.
  3. Submit the files in the temporary storage area to the version library and use git committhe command.
  4. Push the local submission to the remote warehouse, use git pushthe command

The first three steps have been introduced in the previous article, friends who are not familiar with it can read the article I wrote before.

git push [远程仓库名] [本地分支]:[远程分支]
# 如果本地分支和远程分支相同,可以省略":[远程分支]"

insert image description here

This effect shows that the push has been successful, you can enter the remote warehouse to check and verify

5. Pulling from the remote warehouse

Gitee is a platform for multi-person assisted development. If the code in the remote warehouse is newer than the code in our local warehouse, we need to pull the latest code from the remote warehouse

The following commands can be used:

git pull [远程仓库名] [远程分支]:[本地分支]

insert image description here
If the above situation occurs, it means that the remote warehouse has been pulled successfully.

This is the end of the article, thank you for watching!
insert image description here

Guess you like

Origin blog.csdn.net/m0_63463510/article/details/132005478