Home System Tutorial LINUX Git Series (2): Getting Started Guide to Git

Git Series (2): Getting Started Guide to Git

Jan 03, 2024 pm 07:05 PM
linux linux tutorial Red Hat linux system linux command linux certification red hat linux linux 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 of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

vscode terminal command cannot be used vscode terminal command cannot be used Apr 15, 2025 pm 10:03 PM

Causes and solutions for the VS Code terminal commands not available: The necessary tools are not installed (Windows: WSL; macOS: Xcode command line tools) Path configuration is wrong (add executable files to PATH environment variables) Permission issues (run VS Code as administrator) Firewall or proxy restrictions (check settings, unrestrictions) Terminal settings are incorrect (enable use of external terminals) VS Code installation is corrupt (reinstall or update) Terminal configuration is incompatible (try different terminal types or commands) Specific environment variables are missing (set necessary environment variables)

See all articles