리눅스 호스팅 (cPanel) 도움말

Git tutorial and basics

Git is a free and open source distributed version control (DVC) system for software development. The core features of Git have contributed to it quickly becoming one of the mostpopular and powerful DVC systems in use today, particularly among open source communities.

DIFFICULTY

Basic - 1 | Medium - 2 | Advanced - 3

TIME REQUIRED

15 min

RELATED PRODUCTS

Linux-based VPS or dedicated servers
Linux-based shared hosting

Git is a version control system that enables developers to better manage their repositories of code during web development projects. Git is especially adept at branching, staging and distribution of code, as well as ensuring the integrity of a code base.

Branching

One of the most powerful and somewhat unique features Git provides is the ability to work with multiple, completely separate branches of your code without affecting other branches. Development can occur within a unique branch outside of the master branch and be later reintegrated.

Staging

Another fairly unique feature to Git is the intermediary "staging" area where files (or even chunks of code) can be stored before commitment into the repository. This enables multiple edits within the same file to be staged (and therefore committed) on separate occasions if necessary, without the need to commit the entire file after every change is made.

Distribution

Although not unique to Git, as a distributed version control system Git allows virtually any workflow that may best serve you or your team or clients. Git has no built-in requirement for central repositories, making it particularly suited to open source projects and other workflows that benefit from a widely spread developer network.

Integrity

Every object that passes through a Git repository passes through a checksum verification process, both when files are entered in or taken out. This ensures that no part of Git repository can be altered without changing the commit ID, providing assurance that a commit always remains identical to when it was entered.

Let's get started.

Installing Git

Git releases are available for all major operating systems and while Git is typically utilized from the command line, there are numerous GUI clients available across a variety of platforms.

Windows and Mac installation applications are available from the official Git downloads page, while installation on popular Linux system can be performed with a single command:

Installation on Ubuntu/Debian

$ apt-get install git

Installation on Fedora/CentOS

$ yum install git

Getting Started

While the detailed information can be found within the official Git documentation, getting started with your first Git repository is very simple and only requires a few minutes to begin.

Once Git is installed, begin by navigating into an empty directory that will be your root directory for your project. For this example our project will live in the ~/dev/foo directory:

Initializing Git

Adding Changes

Once you've added a file to your project directory, you need to tell Git which files should be entered into the repository and tracked by Git. Here we're adding a data.xml file to the project directory, then using the git add [file] command to tell Git that we want data.xml in the system:

root@Main:~/dev/foo# touch data.xml

root@Main:~/dev/foo# git add data.xml

Status

One of the most common tools in Git is the git status command, which provides information on the overall commitment status of your project. In this case after adding our data.xml file to Git, we see that the file is waiting to be committed:

Committing

After adding files to the repository the next step is to create a commit, which can be performed easily with the git commit command:

root@Main:~/dev/foo# git commit

Note: If this is your first time using Git on this machine you may encounter a warning upon attempting to commit regarding setting your git config user.email and user.name values. If necessary, follow the instructions on screen to set these and retry the commit command.

Once the git commit command is issued, you will typically be presented with a text editor screen in which to edit the commit message. Enter an appropriate message and save to finalize your commit:

While this tutorial should give you a solid grasp on what Git is and how you can potentially use it to improve your version control workflow, we've just scratched the surface of what Git can do and how you can take full advantage of its capabilities.