Home >Development Tools >git >A brief analysis of how to clone a project locally on gitlab

A brief analysis of how to clone a project locally on gitlab

青灯夜游
青灯夜游Original
2023-03-27 20:07:474474browse

How to clone the project locally on gitlab? The following article will introduce to you two correct postures for cloning projects from gitlab and commonly used git visualization tools. I hope it will be helpful to you!

A brief analysis of how to clone a project locally on gitlab

We have created a project in the previous lesson. In this lesson, I will clone the project locally and then practice common git commands

There are two ways to git clone

clone, one is SSH, the other is HTTPS, The main difference between the two cloning methods is:

  • HTTPS only needs to copy the link, and then enter the clone command in git Bash to clone the project locally, but you need to enter the account every time you fetch and push the code and password; when using SSH, by default you do not need to enter the account password for each communication, but you need to configure and add the SSH key before cloning. The prerequisite for adding the SSH key is that you must be the owner of this project.

You can choose to download this code repository directly. After downloading, it will be a compressed package and will not carry the .git file.

Now let’s clone our project first

Use the following command to directlyclone,

git clone git@gitlab.com:fe-test1/git-demo.git

The first time you clone You enter your username and password. If you don’t know what your password is, you can modify it in Edit profiles->password. The picture below shows the success of clone.

Now let’s submit a message to test whether ours can be pushed to the remote warehouse.

Open the project and go to README.mdJust modify some information in the file, and then execute

# 添加代码到暂存区域 .添加所有文件
git add . 
# 提交commit信息 "feat" commit规范,后面章节会介绍
git commit -m "feat: 第一次提交代码"

Use git status to check if there is any uncommitted code, prompting us that it is time to push

Execute git push Push the code to the remote

shows that the push is successful and the code is pushed to the main branch . Then let's go to the panel to see if it's the content we just submitted:

You can see the information we just modified and the commit information we submitted.

OK, reaching this point means that you have taken the first step in the company. I have heard many times that some self-proclaimed master programmers are questioned because they cannot even handle this thing, because many new programmers really don’t know how to do this! ! !

git remote

If we create a project locally, how do we establish a connection with the remote repository? The answer is to use git remote

Similarly, first you have to create a remote warehouse local-test, and then create a folder locally local- test, then add a READMD.md file and add some information casually.

Execute the following command in the root directory of the folder:

# 初始化仓库
git init
# 添加暂存区
git add .
# 提交
git commit -m "feat: 建立与远程仓库的连接"
# 添加远程源信息
git remote add origin git@gitlab.com:fe-test1/local-test.git
# push代码到origin/main分支
git push -u origin main

It is considered successful if the code can be successfully pushed to the remote warehouse.

Summary: Generally, if there is an existing code warehouse, we tend to use the first method more. If we are creating a new warehouse and new project, we will use the second method.

vscode

vscode comes with its own git management tool. When we modify something, we can clearly see which files and contents have been modified,

#There are many operation shortcuts on the left side, including temporary storage, submission, push and other operations.

After installing the gitlens plug-in, you can view other people's submission records, especially when merging conflicts, it is more convenient and faster.

gitkraken

Highly recommend this tool, you can easily create a remote warehouse on this tool, or clone the remote warehouse. Manage local repositories and more. Students who cannot access the Internet may not push the code for a long time. With this tool, you don’t need to worry about network problems at all. You can pull and push large files very quickly.

However, it can only be used on mac?

Download address: www.gitkraken.com/

A brief analysis of how to clone a project locally on gitlab

(Learning video sharing: Basic Programming Video )

The above is the detailed content of A brief analysis of how to clone a project locally on gitlab. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn