【12】Git Tool Collaboration Platform Usage Tutorial Gitee User Guide Tencent Worker Bee User Guide [Gitee] [Tencent Worker Bee] [Git]

Tips: A small number of git installation and usage tutorials, more about quickly getting started with Gitee and the worker bee platform

 

1. Preparation work

1. Download git

   Git - Downloads (git-scm.com)

Find the corresponding operating system, corresponding version, and corresponding number of digits

 

After downloading, install it yourself according to your needs, and then use git --version to verify whether it is successful.

 

2. Obtain SSH key 

Using SSH keys allows you to achieve more secure authentication when communicating with your Git server.

The first one is generated by command (replace the email address and user name with your own)

Set username

git config --global user.name "yourusername"

 Set global user mailbox

git config --global user.email "[email protected]"

Generate secret key based on email 

ssh-keygen -t rsa -b 4096 -C "[email protected]"

The generated secret key will be stored in ~/.ssh/id_rsathe file

The second method uses git GUI

Right-click on a blank folder to enter or enter from the start menu

 Click Show SSH Key

 If there is not one, clicking will automatically create one

If the command has been generated, it will be displayed

3. Upload local projects to the collaborative tool platform

(Here we take gitee and Tencent Worker Bee as examples)

1. Initialization 

Enter the folder where the project is located, create a virtual project folder, and create a Readme file in it

The specific structure is shown in the figure

Right click to enter git bash

 Initialize code repository

git init

At this time, a hidden folder will appear. git This is the execution flag of this command.

2. Tutorial on how to use Gitee and Tencent Worker Bee collaborative tool platform

1、Gitee 

Official website:  Gitee - Enterprise-level DevOps R&D performance platform

Register gitee and log  in - Gitee.com   (I logged in using GitHub)

1. Go to the homepage and click Create Warehouse

 After creation, the address of the warehouse will be displayed.

At the bottom of the page is a tutorial for uploading projects to the warehouse.

 2. Bind SSH

SSH is the permission key for the remote warehouse to obtain local files

Click on Management in the menu bar above the warehouse

Click Add Public Key on the left

 Paste the public key we generated earlier and set the title

Display added successfully

Click to deploy the public key and click to enable

 Pop-up reminder that public key is enabled

3. Upload the local project to the remote warehouse 

We have previously created the project directory testproject and initialized the git repository, so we execute the following command

git add .
git commit -m "first commit" //引号里的为提交的备注
                           
git remote add origin "你的代码仓库地址"  

 Command explanation

 //By executing this command, you tell Git to create an association in your local repository with the remote repository "origin", which is located at "your code repository address". In this way, you can use origin to push, pull, and other interactive operations with the remote warehouse.

This is just a step to associate with the remote repository and does not automatically push or pull code. You need to execute additional Git commands to actually transfer data, such as git push and git pull.

git push -u origin "master"

 Right-click in the root directory of the project to enter GitBash

 Enter commands one at a time

 Upload successful

 At this time, we enter the project in the warehouse to view the local project successfully uploaded to the remote code warehouse. 

How to delete a project (delete the entire repository)

Click to manage

 Click Delete. Note that deletion cannot be restored.

2. Tencent worker bee 

1. Log    in to Worker Bee - Tencent Worker Bee (tencent.com)

 2. First we try to create a project directly

We will find that when filling in the parent path, which is the upper-level folder of this project, you can only select the project group folder or the personal space folder. So the correct sequence is to create a project group first and then create the project

 3. Create a project team

Note that the project team/directory name is unique, and you need to give it a name that no one has ever given. 

After entering the project group, you will see the project and create project buttons under the project members and project group.

 We click to create a project

 The project path is actually the folder where the project is located.

When filling in the project path, you need to pay attention to the following points:

  • The project path is the unique identifier of the project in the warehouse. It must be unique and cannot be repeated with other project paths.
  • The project path usually affects the project's URL. For example, if the project path is my-awesome-project, the project's URL might look like https://yourusername.coding.net/p/my-awesome-project.
  • The project path can use letters, numbers, dashes (-), and underscores (_), and cannot contain spaces or special characters.
  • Project paths are not case sensitive, i.e. myprojectand MyProjectare treated as the same path.

We choose to name it test

At this time, it will be displayed that the creation is successful and the SSH address of the remote warehouse is generated.

 Scroll down the page for specific command instructions.

 We now have an existing project, so select the command to upload the local README.md to the code repository.

 The last command failed to run, reminding us that we did not have sufficient permissions. At this time, we did not bind our SSH key to the remote warehouse. This was caused by our previous preparations. The SSH key had been generated.

We return to the homepage and click on Personal Settings->SSH Key

Or click on the avatar in the upper right corner and click on the small key symbol

 Click to add a secret key

 Paste the secret key we generated previously and set the key name

 At this time, if we execute the push command again, the permission problem will no longer be reported.

When we enter the project team's project, we can see that the local project has been successfully pushed to the remote code repository.

How to delete projects in remote warehouse

Scroll down the page and click Delete Project. Note that project deletion cannot be recovered.

3. Summary:

1. First create an account to create a warehouse (Tencent Worker Bee is the project team) Create a project to obtain the warehouse address (a link string ending with .git)

2. Generate a local SSH key, bind and enable it to the remote warehouse

3. Run the following command (in the directory where the project is located)

git init
git add .
git commit -m "first commit" //引号里的为提交的备注
git remote add origin "你的代码仓库地址" 
git push -u origin "master"

4. Check whether the files in the project are successfully uploaded to the remote warehouse

Next, let’s talk about clone, pull, commit, push, and remote methods:

  • cloneUsed to create local copies.
  • pullUsed to synchronize remote changes to local.
  • commitUsed to save local changes to a new version of the local repository.
  • pushUsed to push commits in the local repository to the remote repository.
  • remoteUsed to manage connections to remote repositories.

4. Clone method:

cloneOrder:

cloneIs the command used to create a local copy of a remote repository.

When cloning a repository, Git copies all files and history of the remote repository to the local computer, enabling modifications and operations to be made locally.

Typically, clonethe command only needs to be run once to create an initial copy of the project.

Example:

git clone https://github.com/user/repo.git

If you encounter a difficult problem and the error message cannot be solved or the file upload is always unsuccessful, you can try the clone method.

Enter a directory

Use the git clone command to download the directory of the remote code repository to the current directory (without double quotes)

git clone "代码仓库地址" "自己想要设置的文件夹名称"  

Enter the generated folder and you can see that there is already a .git file in it

Move your local project directory files to this folder and then execute the command

git add .
git commit -m "你的备注"
git push -u origin "你的备注"

 This way you can also upload successfully

5. pull method

pullOrder:

pullis the command used to get the latest changes from the remote repository and merge them into the current branch.

While working locally, others may have committed changes to the remote repository. pullcommand allows synchronizing these changes to the local repository.

pullIt is actually a combination of two operations: fetch(fetching changes from the remote repository) and merge(merging the fetched changes into the current branch).

Example:

git pull origin master

6. push command

pushOrder:

pushUsed to push commits in the local repository to the remote repository. Remote warehouses are usually hosted on services such as GitHub, GitLab or Bitbucket. Domestic warehouses include gitee, Tencent Worker Bee, etc.

When you have made a series of commits locally and want to share these changes with others, you can use the pushcommand to upload these changes to the remote repository.

Example:

git push origin master

7. commit command

commitOrder:

commitUsed to save local changes to a new version of the local repository. Each commit creates a new commit record that contains the changes you made and a descriptive commit message.

The commit message is a brief description of the changes you made, and should usually clearly explain why the changes were made. Good commit messages are key to collaboration and code maintenance.

Example:

git commit -m "增加了一个css样式"

8.remote command

remoteOrder:

remoteNot a command directly related to cloning or syncing code, but is used to manage connections to remote repositories.

Through remotethe command, you can view the currently configured remote warehouse, add a new remote warehouse, delete a remote warehouse, etc.

It allows setting up multiple remote repositories in a local project to interact with multiple sources simultaneously.

Example:

# 查看当前配置的远程仓库
git remote -v

# 添加一个新的远程仓库
git remote add upstream https://github.com/upstream/repo.git

9. Delete the library (clear the original project folder and upload a new project folder)

Use cdthe command to enter the warehouse directory:

cd <仓库目录>

Delete all files: Use the following command to delete all files in the repository:

git rm -r *

This will delete all files recursively. Note that this only deletes the files from the staging area and working directory, and does not directly affect the remote repository.

Submit changes: Submit the deletion using the following command:

git commit -m "Remove all files"

Push the changes: Finally, use the following command to push the changes to the remote repository:

git push origin <分支名>

 Please <分支名>replace with the name of the branch you want to push to, usually mainor master.

After following these steps, your remote repository should no longer contain any files. Please be careful to avoid accidentally deleting important data. If you just want to clear the files in the remote repository instead of deleting the entire repository, you can also consider creating a new empty commit to achieve the clearing effect.

The more specific steps are

git clone 远程仓库地址

Delete all files in the original project folder

Then click git bash in the same directory as the .git file and enter the command 

git add .

Submit local changes

git commit -m "删除目录下的所有文件"

Push to remote warehouse

git push origin <your-branch-name>

Replace <your-branch-name>with the name of the branch you are using, usually mainor master

This error may be reported when executing push

[session-d244b98b] Auth error: DeployKey does not support push code
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

 You can change the local connection of the remote warehouse from SSH to https form

1. Check permissions: Make sure you have sufficient permissions in the remote code repository to perform push operations. You need to confirm whether your authentication information is correct and whether you have the permission to push to the warehouse. Check whether the personal SSH private key has been bound (the public key only has read-only permission)

2. View the remote warehouse address

git remote -v

3. Change remote warehouse address command

git remote set-url origin <new-remote-url>

 Replace <new-remote-url>with the correct https version remote warehouse address.

4. Push again

git push origin <your-branch-name>

 It worked this time 

At this time, the files in the remote warehouse have been updated and the files that are not in the local project file directory have been deleted. 

3. Use the compiler to automatically perform pull, commit and other operations

1、idea

Open the project directory with idea (at this time, the project has been successfully uploaded and pushed once using the previous steps)

At this time, there is a .git folder idea in the same directory of the project, which can automatically identify the remote warehouse address and branch.

 Click the Git option on the menu bar to perform operations such as Commit, Push, Update Project, etc.

Here is an introduction to what these operations do.

Git operations involve different aspects of version control and code collaboration. Here's their explanation and their differences:

  1. Commit:

    In Git, "commit" refers to the operation of saving your code changes to your local code repository. When you have finished making some code changes, you can git commitcreate a new commit by executing the command. Each commit has a unique identifier (hash) and contains the changes you made along with a descriptive commit message describing the purpose and content of the change.

  2. Push:

    "Push" is the operation of uploading your local commits to the remote repository. Once your code has been committed in your local repository, you can use git pushthe command to push those commits to a connected remote repository (usually something like GitHub, GitLab, Gitee, etc.). This way other collaborators will be able to see your changes and update accordingly in their local repositories.

  3. Pull:

    "Pull" is the operation of pulling changes from the remote repository to your local repository. When other collaborators or team members commit new changes in the remote repository, you can use git pullthe command to pull these changes to your local repository so that you can work based on the latest code when working locally.

  4. Fetch:

    "Fetch" is an operation that fetches the latest changes from a remote repository, but does not automatically merge them into your local branch. With git fetchthe command, you can get new commit and branch information in the remote repository, and then use other commands (such as git mergeor git rebase) to merge these changes into your local branch. In IDEA, the "Pull" operation is actually a combination of "Update" and "Merge". When you perform a "Pull" operation, IDEA will first perform an "Update" operation and then try to merge the new changes in the remote repository with your local changes. If there are conflicts, you need to resolve them.

  5.  Update

      In IDEA, "Update" refers to synchronizing the local repository with the remote repository in order to obtain the latest changes in the remote repository. When you choose to perform an "Update" operation, IDEA will pull new commits from the remote repository and apply these changes to your local branch. This helps keep your local repository in sync with the remote repository.

difference:

  • Commit: Save local changes as a commit, affecting only your local repository.
  • Push: Upload local commits to the remote repository so that others can see your changes.
  • Pull: Merge changes from the remote repository into your local branch to keep your local repository up to date.
  • Fetch: Gets changes from the remote warehouse, but does not automatically merge them. Manual operation is required to apply these changes to your local branch.

The difference between Update and Pull

In IDEA, the "Update" operation is to obtain the latest changes from the remote repository, while the "Pull" operation is to merge the latest changes from the remote repository into the local branch. In most cases, the "Pull" operation consists of the "Update" and "Merge" steps.

How to restore a local project to a previous version

Click git in the lower left corner, select the restored version on the right, and right-click CheckOut Revison to restore it. 

2、visual studio

Open the third icon on the left menu of vs.

There are various operations here

 In daily life, it is submission and push. Note that each submission message is an option that must be filled in.

The git related information displayed in the bottom column shows a circular circle, which means that the link to the remote code repository is successful, otherwise there is no

 

Guess you like

Origin blog.csdn.net/qq_53478650/article/details/132197613