Installing and Getting Started with Git on Debian 10

29/12/2020
Git
Git is a very popular Version Control System (VCS). It is used to track changes in source codes during software development. It is a really helpful tool for rapid software development. Git is very fast at doing its job. It is one of the best tools a developer can have if utilized properly. Git is totally open source.

In this article, I am going to show you how to install Git on Debian 10 Buster and how to get started with Git. So, let’s get started.

Installing Git:

Git is available in the official package repository of Debian 10. So, you can easily install Git on Debian 10 using the APT package manager.

First, updae the APT package repository cache with the following command:

$ sudo apt update

The APT package repository cache should be updated.

Now, install Git from the official Debian 10 package repository with the following command:

$ sudo apt install git

Now, press Y and then press <Enter> to confirm the installation.

APT should download and install all the required packages.

At this point, Git should be installed.

Once Git is installed, check whether Git is working with the following command:

$ git –version

As you can see, I am running Git 2.20.1 on my Debian 10 machine. It’s working correctly.

Setting Up Global Git Username and Email:

The first thing you should do after installing Git is to set up a global Git username and email. This username and email will be used in your Git repositories by default.

To set up a global Git username, run the following command:

$ git config –global user.name "YOUR_NAME"

NOTE: Replace YOUR_NAME with your own name.

To set up a global Git email, run the following command:

$ git config –global user.email "YOUR_EMAIL"

NOTE: Replace YOUR_EMAIL with your own email address.

Now, check whether the global username and email is set with the following command:

$ git config –global -l

As you can see, the global user.name and user.email is correctly set.

Git Terms:

In order to understand Git, you should be familiar with some of the common Git terms.

Repository: It is a directory on your local computer or a remote server where all your project files are kept and tracked by Git.

Untracked: If you create a new file on your Git repository, then it is called an untracked file in Git. Unless you tell git to track it, Git won’t track a file.

Tracked: If you want Git to track a file, then you have to tell Git to track the file manually.

Staged: Before you commit your changes to the Git repository, you must add the files to the staging area. The files in the staging area is called staged files.

Modified: If you add a file in the staging area, and modify the file again before committing, then the file will have a modified status. You will have to add the file to the staging area again for you to be able to commit it.

Commit: It is keeping a snapshot of the files that are in the staging area. A commit has information such as a title, description, author name, email, hash etc.

Basic Git Workflow:

In this section, I am going to show you the basic Git workflow. I am going to create a new Git repository on my local filesystem, and start developing a simple Node.js project on that repository and use Git to track changes in my project. So, let’s get started.

First, make a new project directory hello-node/ and navigate to the project directory with the following commands:

$ mkdir hello-node
$ cd hello-node/

Now, initialize a new Git repository in the project directory with the following command:

$ git init

As you can see, a new empty Git repository is initialized.

Now, create a new file hello.js and type in the following lines of code in it.

console.log(“Hello from LinuxHint!”);

Now, to see the status of the files in the Git repository, run the following command:

$ git status

As you can see, the file hello.js is marked red. Which means it’s an untracked file.

Now, to track the file hello.js, run the following command:

$ git add hello.js

NOTE: If you have a lot of files in your project directory that you want to track, then you don’t have to run git add for each of the files. Instead you can run the following command to track them all.

$ git add .

Now, check the status of the files with the following command:

$ git status

As you can see, the file is now marked green, which means Git is tracking the file and the file is staged. It’s ready to be committed.

Now, to commit the changes, run the following command:

$ git commit

A text editor should be opened. Now, type in a commit message. It could be anything. But it should help you remember what you did here. Ignore the lines starting with #. These are comments and won’t be added to the actual commit.

Once you’ve written the commit message, press <Ctrl> + X followed by Y and <Enter> to save the file.

The changes should be committed.

You can list all the existing commits with the following command:

$ git log –oneline

As you can see, the commit I’ve added is listed here. Each commit has its own hash and the hash is unique throughout the project. In this particular commit, the hash is 1edc2d2. This is the short form of the hash. It is enough to uniquely identify each commits.

If you want to see the long form of the hash, then list the existing commits with the following command:

$ git log

As you can see, more information about each commit is listed. Also, the hash is printed in the long form.

You can further modify existing files, add new files, track them, stage them, add new commits and so on to develop your project.

So, that’s how you install Git on Debian 10 Buster and get started with Git on Debian 10. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Install GitLab on Ubuntu 18.04

With the recent acquisition of GitHub by Microsoft, many corporations and organisations have decided to migrate away from...
28/12/2020

5 Best Self-hosted GitHub Alternatives

GitHub may be the most popular computer code hosting service for version control using Git, which is a distributed version...
29/12/2020

How to Install and Configure GitLab on Debian 9

Recently Microsoft bought GitHub. Those of you Microsoft haters may say GitHub is not trustable anymore. Well, I won’t...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Mua proxy v4 chạy socks5 để chơi game an toàn, tốc độ cao ở đâu?
18/05/2024

Thuê mua proxy Telegram trọn gói, tốc độ cao, giá siêu hời
18/05/2024

Thuê mua proxy Viettel ở đâu uy tín, chất lượng và giá tốt? 
14/05/2024

Dịch vụ thuê mua proxy US UK uy tín, chất lượng số #1
13/05/2024

Thuê mua proxy Việt Nam: Báo giá & các thông tin MỚI NHẤT
13/05/2024