search
HomeSystem TutorialLINUXGit Series (2): Getting Started Guide to Git
Git Series (2): Getting Started Guide to GitJan 03, 2024 pm 07:05 PM
linuxlinux tutorialRed Hatlinux systemlinux commandlinux certificationred hat linuxlinux video

Introduction Because Git is so popular, if you can at least be familiar with some basic Git knowledge, it can bring a lot of convenience to your life. If you can master the basics of Git (you can, I swear!), then you'll be able to download anything you need and maybe even make some contributions in return. After all, that's the essence of open source: you have access to the code of the software you use, the freedom to share it with others, and the right to modify it if you wish. Git makes this easy once you get familiar with it.

Git 系列(二):初步了解 Git

Read and write

Generally speaking, there are two ways to interact with a Git repository: you can read from the repository, or you can write to the repository. It's like a file: sometimes you open a document just to read it, and other times you open it because you need to make some changes.
This article only explains how to read from the Git repository. We will cover the topic of writing back to a Git repository in a later article.

Git or GitHub

One sentence to clarify: Git is different from GitHub (or GitLab, or Bitbucket). Git is a command line program, so it looks like this:

  1. $ git
  2. usage: Git [--version] [--help] [-C ]
  3. [-p | --paginate | --no-pager] [--bare]
  4. [--Git-dir=] []

Because Git is open source, many smart people have built basic software around it; these basic software, including around themselves, have become very popular.
My article series will start by teaching you pure Git knowledge, because once you understand what Git is doing, then you don't need to care about what front-end tool you are using. However, my article series will also cover common ways to accomplish each task through popular Git services, since those will likely be the first ones you'll encounter.

Install Git

On Linux systems, you can obtain and install Git from the distribution software repository you are using. BSD users should look for Git in the devel section of the Ports tree.
For closed source operating systems, please go to its official project website and install according to the instructions. Once installed, there should be no difference in the commands on Linux, BSD, and Mac OS X. Windows users will need to adjust Git commands to match Windows file systems, or install Cygwin to run Git natively without being hampered by Windows file system translation issues.

Git Afternoon Tea

Not everyone needs to add Git to our daily life right away. Sometimes, your most interaction with Git is to access a repository, download a file or two, and then never use it again. Think of Git this way, it's more like afternoon tea than a formal banquet. You have some polite conversation, get the information you need, and then you go away and you don't want to talk like this anymore for at least the next three months.
Of course, that's okay.
Generally speaking, there are two ways to access Git: using the command line, or using one of those amazing Internet technologies for quick and easy access through a web browser.
Let's say you want to install a recycle bin for your terminal because you've been destroyed by the rm command too many times. You may have heard of Trashy, which calls itself a "sane rm command middleman", and maybe you want to read its documentation before installing it. Luckily, Trashy is hosted publicly on GitLab.com.

Landgrab

The first step in our work is to use the landgrab sorting method on this Git repository: we will clone the complete repository and then sort according to the content. Since the repository is hosted on a public Git service platform, there are two ways to get the job done: using the command line, or using the web interface.
To get the entire repository using Git, use the git clone command and the URL of the Git repository as parameters. If you don't know what the correct URL is, the repository should tell you. GitLab provides you with a copy-and-paste URL to the Trashy repository.

Git 系列(二):初步了解 Git
You may have noticed that on some service platforms, both SSH and HTTPS links are provided. You can use SSH only if you have write access to the repository. Otherwise, you must use an HTTPS URL.
Once you get the correct URL, cloning the repository is very easy. Just git clone the URL, and an optional directory specifying the directory to be cloned to. By default the git directory will be cloned into the directory you are currently in; for example, 'trashy.git' will be cloned into the 'trashy' directory in your current location. I use the .clone extension to mark repositories that are read-only, and the .git extension to mark repositories that I can read and write to, but this is not officially required.
  1. $ git clone https://gitlab.com/trashy/trashy.git trashy.clone
  2. Cloning into 'trashy.clone'...
  3. remote: Counting objects: 142, done.
  4. remote: Compressing objects: 100% (91/91), done.
  5. remote: Total 142 (delta 70), reused 103 (delta 47)
  6. Receiving objects: 100% (142/142), 25.99 KiB | 0 bytes/s, done.
  7. Resolving deltas: 100% (70/70), done.
  8. Checking connectivity... done.

Once you have successfully cloned the repository, you can browse the files in the repository just like any other directory on your computer.

Another way to obtain a copy of the repository is to use the web interface. Both GitLab and GitHub provide a warehouse snapshot file in .zip format. GitHub has a big green download button, but in GitLab, you can find the inconspicuous download button on the right side of the browser.

Git 系列(二):初步了解 Git Choose carefully

Another way to get files from a Git repository is to find the file you want and then pull it out of the repository. Only the web interface provides this method, and essentially, what you see is a clone of someone else's repository; you can think of it as an HTTP shared directory.
The problem with using this method is that you may find that some files do not exist in the original repository, because the complete form of the file may not be built until you execute the make command. That is only if you download the complete repository and read the README. Or INSTALL file, and then run the relevant commands to generate it. However, if you're sure the file exists and you just want to go into the repository, get that file, and then leave, you can do that.
In GitLab and GitHub, click the file link and view it in Raw mode, then use your web browser's save function, for example: in Firefox, File > Save Page As. In a GitWeb repository (which is a private git repository web viewer used by some people who prefer to host git themselves), the Raw view link is in the file list view.

Git 系列(二):初步了解 Git

Best Practices

It is generally believed that the correct way to interact with Git is to clone the complete Git repository. There are several reasons for thinking this way. First, you can easily keep your cloned repository updated using the git pull command, so you don't have to go back to the web site to get a fresh copy every time a file changes. Second, if you happen to need to make some improvements, as long as you keep the repository clean, you can submit the changes to the original author very easily.
Now, it might be time to practice finding Git repositories of interest and then cloning them to your hard drive. As long as you know the basics of using the terminal, it's not too difficult to do. Still don’t know how to use the basic terminal? Then give me 5 more minutes.

Terminal usage

The first thing to know is that all files have a path. This makes sense; if I ask you to open a file for me in a regular non-terminal environment, you have to navigate to the file's location on your hard drive, and until you find that file, you have to navigate through a bunch of windows. For example, you might click on your Home Directory > Images > InktoberSketches > monkey.kra.
In that case, the path to the file monkeysketch.kra is: $HOME/Pictures/InktoberSketches/monkey.kra.
In the terminal, unless you're doing some special sysadmin tasks, your file paths usually start with $HOME (or, if you're lazy, use the ~ character), followed by a list of folders up to the filename itself.
This is similar to how you click on various icons in a GUI until you find the relevant file or folder.
If you want to clone the Git repository to your documents directory, then you can open a terminal and run the following command:

  1. $ git clone https://gitlab.com/foo/bar.git
  2. $HOME/Documentation/bar.clone

Once the cloning is complete, you can open a file manager window, navigate to your Documents folder, and you will find the bar.clone directory waiting for you to access.
If you want to get more advanced, you may want to visit that repository again in the future, and you can try using the git pull command to see if the project has been updated:

  1. $ cd $HOME/Documentation/bar.clone
  2. $ pwd
  3. bar.clone
  4. $ git pull

So far, that’s all the terminal commands you need to know initially, so go explore. The more you practice, the better you get at Git (practice makes perfect), that's the point and the nature of the matter.

The above is the detailed content of Git Series (2): Getting Started Guide to Git. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Linux就该这么学. If there is any infringement, please contact admin@php.cn delete
什么是linux设备节点什么是linux设备节点Apr 18, 2022 pm 08:10 PM

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

Linux中open和fopen的区别有哪些Linux中open和fopen的区别有哪些Apr 29, 2022 pm 06:57 PM

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

linux中什么叫端口映射linux中什么叫端口映射May 09, 2022 pm 01:49 PM

端口映射又称端口转发,是指将外部主机的IP地址的端口映射到Intranet中的一台计算机,当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上;可以通过使用动态或固定的公共网络IP路由ADSL宽带路由器来实现。

什么是linux交叉编译什么是linux交叉编译Apr 29, 2022 pm 06:47 PM

在linux中,交叉编译是指在一个平台上生成另一个平台上的可执行代码,即编译源代码的平台和执行源代码编译后程序的平台是两个不同的平台。使用交叉编译的原因:1、目标系统没有能力在其上进行本地编译;2、有能力进行源代码编译的平台与目标平台不同。

linux中eof是什么linux中eof是什么May 07, 2022 pm 04:26 PM

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

linux怎么查询mac地址linux怎么查询mac地址Apr 24, 2022 pm 08:01 PM

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。

linux怎么判断pcre是否安装linux怎么判断pcre是否安装May 09, 2022 pm 04:14 PM

在linux中,可以利用“rpm -qa pcre”命令判断pcre是否安装;rpm命令专门用于管理各项套件,使用该命令后,若结果中出现pcre的版本信息,则表示pcre已经安装,若没有出现版本信息,则表示没有安装pcre。

linux中rpc是什么意思linux中rpc是什么意思May 07, 2022 pm 04:48 PM

在linux中,rpc是远程过程调用的意思,是Reomote Procedure Call的缩写,特指一种隐藏了过程调用时实际通信细节的IPC方法;linux中通过RPC可以充分利用非共享内存的多处理器环境,提高系统资源的利用率。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!